Skip to content

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

Merged
merged 5 commits into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/datascience-ui/native-editor/nativeCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() && !isCellNavigationKeyboardEvent(e)) {
Copy link

@DonJayamanne DonJayamanne Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be checked only if !this.isFocused()
Cuz if a cell is focused, then k might do something else..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unfamiliar with the intended behavior here, but isn't that check already done in onOuterKeyDown?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore the comment, thats why i striked it out.

return;
}
const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting;
switch (e.code) {
case 'ArrowUp':
Expand Down Expand Up @@ -886,3 +889,15 @@ export class NativeCell extends React.Component<INativeCellProps> {
export function getConnectedNativeCell() {
return connect(null, actionCreators)(NativeCell);
}

function isCellNavigationKeyboardEvent(e: IKeyboardEvent) {
return (
e.code === 'Enter' ||
e.code === 'NumpadEnter' ||
e.code === 'ArrowUp' ||
e.code === 'k' ||
e.code === 'ArrowDown' ||
e.code === 'j' ||
e.code === 'Escape'
);
}