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
Update code editor to clear tooltips on 'Escape' key press, adjust code cell active line contrast in dark mode and optimize tooltip height (#271)
Myles Scolnick40a653ca3097
diff --git a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snapindex 64605d6bcb..cfc4a6b465 100644--- a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap+++ b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap@@ -52,6 +52,10 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `"key": "Escape","run": "closeCompletion",},+ {+ "key": "Escape",+ "run": "clearTooltips",+ },{"key": "Escape","run": "simplifySelection",@@ -156,6 +160,10 @@ exports[`snapshot all duplicate keymaps > vim keymaps 2`] = `"key": "Escape","run": "closeCompletion",},+ {+ "key": "Escape",+ "run": "clearTooltips",+ },{"key": "Escape","run": "simplifySelection",diff --git a/frontend/src/core/codemirror/__tests__/setup.test.ts b/frontend/src/core/codemirror/__tests__/setup.test.tsindex 30a4866304..75a1e7201d 100644--- a/frontend/src/core/codemirror/__tests__/setup.test.ts+++ b/frontend/src/core/codemirror/__tests__/setup.test.ts@@ -88,7 +88,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("18");+ expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("19");expect(duplicates).toMatchSnapshot();});@@ -101,7 +101,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("17");+ expect(Object.values(duplicates).flat().length).toMatchInlineSnapshot("18");expect(duplicates).toMatchSnapshot();});});diff --git a/frontend/src/core/codemirror/completion/hints.ts b/frontend/src/core/codemirror/completion/hints.tsindex 4d5be9f575..58dca9cad4 100644--- a/frontend/src/core/codemirror/completion/hints.ts+++ b/frontend/src/core/codemirror/completion/hints.ts@@ -5,11 +5,12 @@ import {Tooltip,hasHoverTooltips,hoverTooltip,+ keymap,showTooltip,} from "@codemirror/view";import { AUTOCOMPLETER, Autocompleter } from "./Autocompleter";import { Logger } from "@/utils/Logger";-import { StateField, StateEffect } from "@codemirror/state";+import { StateField, StateEffect, Prec } from "@codemirror/state";export function hintTooltip() {return [@@ -67,6 +68,14 @@ export function hintTooltip() {}),cursorTooltipField,+ Prec.highest(+ keymap.of([+ {+ key: "Escape",+ run: clearTooltips,+ },+ ])+ ),// Clear tooltips on blurEditorView.domEventObservers({blur: (event, view) => {@@ -87,10 +96,15 @@ export function dispatchShowTooltip(view: EditorView, tooltip: Tooltip): void {});}-function clearTooltips(view: EditorView): void {- view.dispatch({- effects: TooltipFromCompletionApi.of([]),- });+function clearTooltips(view: EditorView): boolean {+ const hasCompletionTooltip = view.state.field(cursorTooltipField).length > 0;+ if (hasCompletionTooltip) {+ view.dispatch({+ effects: TooltipFromCompletionApi.of([]),+ });+ return true;+ }+ return false;}// Effect that dispatches a tooltipdiff --git a/frontend/src/css/Cell.css b/frontend/src/css/Cell.cssindex db00f0f27d..376ddb36b4 100644--- a/frontend/src/css/Cell.css+++ b/frontend/src/css/Cell.css@@ -226,7 +226,7 @@}.dark .Cell .cm-editor.cm-focused .cm-activeLine {- background: hsl(210deg 100% 2% / 75%);+ background: hsl(210deg 100% 2% / 20%);}.Cell .cm-editor .cm-activeLine {@@ -346,7 +346,6 @@.Cell.needs-run:focus-within .cm-editor {box-shadow: none;border: 1px solid transparent;- border-radius: 0;}.Cell.needs-run .output-area {diff --git a/frontend/src/css/codemirror.css b/frontend/src/css/codemirror.cssindex 38807c89c4..c016e5d9b5 100644--- a/frontend/src/css/codemirror.css+++ b/frontend/src/css/codemirror.css@@ -1,14 +1,10 @@-.cm-selectionBackground {+.light .cm-selectionBackground {/* This is the background for selected text when focused,but we want to use it when not in focus either because wewill often lose focus during find/replace or in another editor */background-color: #d7d4f0 !important;}-.dark .cm-selectionBackground {- background-color: #4d4d4d !important;-}-/* -- Gutters -- */.cm .cm-gutters {@@ -46,7 +42,7 @@.cm .cm-tooltip.cm-tooltip-hover,.cm .cm-tooltip.mo-cm-tooltip,.cm .cm-tooltip.cm-completionInfo {- max-height: 800px;+ max-height: 45vh; /* 45% of viewport height */overflow: auto;/* Respect newlines. */