From f1d2e8f63709ab4ce11a571f7e0634e56eeb4b58 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Sun, 12 Jul 2020 17:20:20 -0700 Subject: [PATCH 1/5] Disable jupyter shortcuts for untrusted notebooks --- src/datascience-ui/native-editor/nativeCell.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index 39f97b3f7090..a3e0a14b1d7f 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -281,6 +281,9 @@ export class NativeCell extends React.Component { // tslint:disable-next-line: cyclomatic-complexity max-func-body-length private keyDownInput = (cellId: string, e: IKeyboardEvent) => { + if (!this.isNotebookTrusted()) { + return; + } const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting; switch (e.code) { case 'ArrowUp': From 03ca8464a5c4abb39bf8dad409e05f0a76520d01 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Sun, 12 Jul 2020 22:29:35 -0700 Subject: [PATCH 2/5] Whitelist some jupyter keystrokes --- src/datascience-ui/native-editor/nativeCell.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index a3e0a14b1d7f..9219a157d530 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -281,7 +281,7 @@ export class NativeCell extends React.Component { // tslint:disable-next-line: cyclomatic-complexity max-func-body-length private keyDownInput = (cellId: string, e: IKeyboardEvent) => { - if (!this.isNotebookTrusted()) { + if (!this.isNotebookTrusted() && isNotWhitelistedCommand(e)) { return; } const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting; @@ -889,3 +889,14 @@ export class NativeCell extends React.Component { 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' + ); +} From dfb3fab1153dbed5c4bd08cab827fd2f62c302d1 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 08:23:33 -0700 Subject: [PATCH 3/5] Don's feedback --- src/datascience-ui/native-editor/nativeCell.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index 9219a157d530..8ab93d327823 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -281,7 +281,7 @@ export class NativeCell extends React.Component { // tslint:disable-next-line: cyclomatic-complexity max-func-body-length private keyDownInput = (cellId: string, e: IKeyboardEvent) => { - if (!this.isNotebookTrusted() && isNotWhitelistedCommand(e)) { + if (!this.isNotebookTrusted() && isNotCellNavigationKeyboardEvent(e)) { return; } const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting; @@ -890,7 +890,7 @@ export function getConnectedNativeCell() { return connect(null, actionCreators)(NativeCell); } -function isNotWhitelistedCommand(e: IKeyboardEvent) { +function isNotCellNavigationKeyboardEvent(e: IKeyboardEvent) { return ( e.code !== 'Enter' && e.code !== 'NumpadEnter' && From dead27afba7febbc0bd55d77831befe183735968 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 10:07:46 -0700 Subject: [PATCH 4/5] Fixes --- src/datascience-ui/native-editor/nativeCell.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index 8ab93d327823..df7af985948b 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -281,7 +281,7 @@ export class NativeCell extends React.Component { // tslint:disable-next-line: cyclomatic-complexity max-func-body-length private keyDownInput = (cellId: string, e: IKeyboardEvent) => { - if (!this.isNotebookTrusted() && isNotCellNavigationKeyboardEvent(e)) { + if (!this.isNotebookTrusted() && !isCellNavigationKeyboardEvent(e)) { return; } const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting; @@ -890,11 +890,12 @@ export function getConnectedNativeCell() { return connect(null, actionCreators)(NativeCell); } -function isNotCellNavigationKeyboardEvent(e: IKeyboardEvent) { +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' From 4559a2e9bdaedf0229d5e287fba3b281307393ee Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Mon, 13 Jul 2020 10:38:55 -0700 Subject: [PATCH 5/5] Oops --- src/datascience-ui/native-editor/nativeCell.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index df7af985948b..77fe2ad356db 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -892,12 +892,12 @@ export function getConnectedNativeCell() { 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' + e.code === 'Enter' || + e.code === 'NumpadEnter' || + e.code === 'ArrowUp' || + e.code === 'k' || + e.code === 'ArrowDown' || + e.code === 'j' || + e.code === 'Escape' ); }