A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: close completion without going into command mode (#6059)
Myles Scolnick85f94e190804
diff --git a/frontend/src/components/editor/navigation/__tests__/navigation.test.ts b/frontend/src/components/editor/navigation/__tests__/navigation.test.tsindex 2aba642d9b..8d89bbc93e 100644--- a/frontend/src/components/editor/navigation/__tests__/navigation.test.ts+++ b/frontend/src/components/editor/navigation/__tests__/navigation.test.ts@@ -1635,7 +1635,7 @@ describe("useCellEditorNavigationProps", () => {const mockEditorView = {current: {state: {- selection: { main: { from: 5, to: 5 } },+ selection: { main: { from: 5, to: 5, empty: true } },field: vi.fn().mockReturnValue({ active: [{ state: 1 }] }), // Mock active completion},dispatch: vi.fn(),diff --git a/frontend/src/components/editor/navigation/navigation.ts b/frontend/src/components/editor/navigation/navigation.tsindex 4390c55a77..c4f1551721 100644--- a/frontend/src/components/editor/navigation/navigation.ts+++ b/frontend/src/components/editor/navigation/navigation.ts@@ -628,8 +628,7 @@ export function useCellEditorNavigationProps(const view = editorView.current;const state = view.state;- const hasTextSelection =- state.selection.main.from !== state.selection.main.to;+ const hasTextSelection = !state.selection.main.empty;if (hasTextSelection) {view.dispatch({diff --git a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snapindex 1c642c51c0..24498e58dc 100644--- a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap+++ b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap@@ -61,10 +61,6 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `},],"Escape": [- {- "key": "Escape",- "run": "closeCompletionAndPropagate",- },{"key": "Escape","run": "simplifySelection",@@ -74,11 +70,6 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `"preventDefault": false,"run": "closeFindReplacePanel",},- {- "key": "Escape",- "preventDefault": true,- "run": "run",- },],"PageDown": [{@@ -177,10 +168,6 @@ exports[`snapshot all duplicate keymaps > vim keymaps 2`] = `},],"Escape": [- {- "key": "Escape",- "run": "closeCompletionAndPropagate",- },{"key": "Escape","run": "simplifySelection",diff --git a/frontend/src/core/codemirror/__tests__/setup.test.ts b/frontend/src/core/codemirror/__tests__/setup.test.tsindex ceed7f3e04..a353c9a625 100644--- a/frontend/src/core/codemirror/__tests__/setup.test.ts+++ b/frontend/src/core/codemirror/__tests__/setup.test.ts@@ -113,7 +113,7 @@ describe("snapshot all duplicate keymaps", () => {);// Total duplicates:// if this changes, please make sure to validate they are not conflicting- expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("20");+ expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("18");expect(duplicates).toMatchSnapshot();});@@ -126,7 +126,7 @@ describe("snapshot all duplicate keymaps", () => {);// Total duplicates:// if this changes, please make sure to validate they are not conflicting- expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("19");+ expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("18");expect(duplicates).toMatchSnapshot();});});diff --git a/frontend/src/core/codemirror/completion/keymap.ts b/frontend/src/core/codemirror/completion/keymap.tsindex 80532ee96d..1afd78c4ba 100644--- a/frontend/src/core/codemirror/completion/keymap.ts+++ b/frontend/src/core/codemirror/completion/keymap.ts@@ -2,12 +2,10 @@import {acceptCompletion,- closeCompletion,completionKeymap as defaultCompletionKeymap,moveCompletionSelection,} from "@codemirror/autocomplete";import { type Extension, Prec } from "@codemirror/state";-import type { EditorView } from "@codemirror/view";import { keymap } from "@codemirror/view";import { isInVimMode } from "../utils";@@ -29,15 +27,6 @@ export function completionKeymap(): Extension {(binding) => !KEYS_TO_REMOVE.has(binding.key),);- const closeCompletionAndPropagate = (view: EditorView): boolean => {- const status = closeCompletion(view);- // When in vim mode, we need to propagate Escape to exit insert mode.- if (isInVimMode(view)) {- return false;- }- return status;- };-return Prec.highest(keymap.of([...withoutKeysToRemove,@@ -48,10 +37,6 @@ export function completionKeymap(): Extension {// of the Escape key, so downstream hotkeys (like leaving insert mode) will work.//// This happens when using Vim.- {- key: "Escape",- run: closeCompletionAndPropagate,- },// Vim-specific completion keybindings{key: "Ctrl-y",diff --git a/frontend/src/core/codemirror/keymaps/keymaps.ts b/frontend/src/core/codemirror/keymaps/keymaps.tsindex 664cec9c0d..64f7b4d971 100644--- a/frontend/src/core/codemirror/keymaps/keymaps.ts+++ b/frontend/src/core/codemirror/keymaps/keymaps.ts@@ -29,23 +29,7 @@ export function keymapBundle(): Extension[] {switch (config.preset) {case "default":- return [- keymap.of(defaultKeymap()),- keymap.of(overrideKeymap(hotkeys)),- // Should be the last thing to close when Escape is pressed- Prec.low(- keymap.of([- {- key: "Escape",- preventDefault: true,- run: (cm) => {- cm.contentDOM.blur();- return true;- },- },- ]),- ),- ];+ return [keymap.of(defaultKeymap()), keymap.of(overrideKeymap(hotkeys))];case "vim":return [keymap.of(defaultVimKeymap()),