Skip to content

Commit 68f4bb0

Browse files
authored
Disable keydown on native cells in untrusted notebooks (#12914)
1 parent 6f153f8 commit 68f4bb0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/datascience-ui/native-editor/nativeCell.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ export class NativeCell extends React.Component<INativeCellProps> {
281281

282282
// tslint:disable-next-line: cyclomatic-complexity max-func-body-length
283283
private keyDownInput = (cellId: string, e: IKeyboardEvent) => {
284+
if (!this.isNotebookTrusted() && !isCellNavigationKeyboardEvent(e)) {
285+
return;
286+
}
284287
const isFocusedWhenNotSuggesting = this.isFocused() && e.editorInfo && !e.editorInfo.isSuggesting;
285288
switch (e.code) {
286289
case 'ArrowUp':
@@ -886,3 +889,15 @@ export class NativeCell extends React.Component<INativeCellProps> {
886889
export function getConnectedNativeCell() {
887890
return connect(null, actionCreators)(NativeCell);
888891
}
892+
893+
function isCellNavigationKeyboardEvent(e: IKeyboardEvent) {
894+
return (
895+
e.code === 'Enter' ||
896+
e.code === 'NumpadEnter' ||
897+
e.code === 'ArrowUp' ||
898+
e.code === 'k' ||
899+
e.code === 'ArrowDown' ||
900+
e.code === 'j' ||
901+
e.code === 'Escape'
902+
);
903+
}

0 commit comments

Comments
 (0)