- Notifications
You must be signed in to change notification settings - Fork 1.3k
Disable keydown on native cells in untrusted notebooks #12914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -281,6 +281,9 @@ export class NativeCell extends React.Component<INativeCellProps> { | |
| | ||
| // tslint:disable-next-line: cyclomatic-complexity max-func-body-length | ||
| private keyDownInput = (cellId: string, e: IKeyboardEvent) => { | ||
| if (!this.isNotebookTrusted() && isNotWhitelistedCommand(e)) { | ||
| return; | ||
| } | ||
| const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting; | ||
| switch (e.code) { | ||
| case 'ArrowUp': | ||
| | @@ -886,3 +889,14 @@ export class NativeCell extends React.Component<INativeCellProps> { | |
| export function getConnectedNativeCell() { | ||
| return connect(null, actionCreators)(NativeCell); | ||
| } | ||
| | ||
| function isNotWhitelistedCommand(e: IKeyboardEvent) { | ||
| ||
| return ( | ||
| e.code !== 'Enter' && | ||
| e.code !== 'NumpadEnter' && | ||
| e.code !== 'ArrowUp' && | ||
| e.code !== 'ArrowDown' && | ||
| e.code !== 'j' && | ||
| e.code !== 'Escape' | ||
| ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we need a better property. I think what we're after is
readonly.I.e. if a cell is readonly, then some keyboard shortcuts cannot be handled & the like.
Cuz the requirement is
when a notebook is not trusted, then treat it as readonly, right now,when a notebook is not trusted, then ignore some keys, etc.I know its laet for this change to be made, hence I wouldn't change it now, as it needs to be done across the UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd agree with this. I think that it's going to be easy to accidentally add a new key / command in the future and possibly enable something for an untrusted notebook that we don't want enable.