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: stop mac completion bindings from stealing backticks (#8829)
Péter Gyarmaticde66acea3f7
diff --git a/frontend/src/core/codemirror/completion/__tests__/keymap.test.ts b/frontend/src/core/codemirror/completion/__tests__/keymap.test.tsindex a35a4f109c..0366e6222e 100644--- a/frontend/src/core/codemirror/completion/__tests__/keymap.test.ts+++ b/frontend/src/core/codemirror/completion/__tests__/keymap.test.ts@@ -1,44 +1,24 @@/* Copyright 2026 Marimo. All rights reserved. */-import { EditorState } from "@codemirror/state";-import { EditorView } from "@codemirror/view";-import { describe, expect, it, vi } from "vitest";-import { completionKeymap } from "../keymap";+import { completionKeymap as defaultCompletionKeymap } from "@codemirror/autocomplete";+import { describe, expect, it } from "vitest";+import { filterCompletionBindings } from "../keymap";describe("completionKeymap", () => {- it("should propagate Escape key when completion is pending", () => {- const state = EditorState.create({- extensions: [completionKeymap()],- });- const view = new EditorView({ state });-- // Mock completionStatus to return "pending"- vi.spyOn(view.state, "field").mockReturnValue("pending");-- view.dispatch({ changes: [], effects: [], annotations: [] });- const result = false; // Mock the expected result-- // Should return false to propagate the Escape key- expect(result).toBe(false);-- view.destroy();+ it("upstream includes the macOS-only completion bindings we care about", () => {+ expect(+ defaultCompletionKeymap.some((binding) => binding.mac === "Alt-`"),+ ).toBe(true);+ expect(+ defaultCompletionKeymap.some((binding) => binding.mac === "Alt-i"),+ ).toBe(true);});- it("should not propagate Escape key when completion is active", () => {- const state = EditorState.create({- extensions: [completionKeymap()],- });- const view = new EditorView({ state });-- // Mock completionStatus to return "active"- vi.spyOn(view.state, "field").mockReturnValue("active");-- view.dispatch({ changes: [], effects: [], annotations: [] });- const result = true; // Mock the expected result-- // Should return true to stop propagation- expect(result).toBe(true);+ it("removes Alt-backtick and Escape while keeping Alt-i", () => {+ const filtered = filterCompletionBindings(defaultCompletionKeymap);- view.destroy();+ expect(filtered.some((binding) => binding.mac === "Alt-`")).toBe(false);+ expect(filtered.some((binding) => binding.key === "Escape")).toBe(false);+ expect(filtered.some((binding) => binding.mac === "Alt-i")).toBe(true);});});diff --git a/frontend/src/core/codemirror/completion/keymap.ts b/frontend/src/core/codemirror/completion/keymap.tsindex 77fdeb291a..7c22f45727 100644--- a/frontend/src/core/codemirror/completion/keymap.ts+++ b/frontend/src/core/codemirror/completion/keymap.ts@@ -6,7 +6,7 @@ import {moveCompletionSelection,} from "@codemirror/autocomplete";import { type Extension, Prec } from "@codemirror/state";-import { keymap } from "@codemirror/view";+import { type KeyBinding, keymap } from "@codemirror/view";import { isInVimMode } from "../utils";const KEYS_TO_REMOVE = new Set<string | undefined>([@@ -22,10 +22,20 @@ const KEYS_TO_REMOVE = new Set<string | undefined>(["Alt-`",]);-export function completionKeymap(): Extension {- const withoutKeysToRemove = defaultCompletionKeymap.filter(- (binding) => !KEYS_TO_REMOVE.has(binding.key),+function hasRemovedKeybinding(binding: KeyBinding): boolean {+ return [binding.key, binding.mac, binding.linux, binding.win].some((key) =>+ KEYS_TO_REMOVE.has(key),);+}++export function filterCompletionBindings(+ bindings: readonly KeyBinding[],+): readonly KeyBinding[] {+ return bindings.filter((binding) => !hasRemovedKeybinding(binding));+}++export function completionKeymap(): Extension {+ const withoutKeysToRemove = filterCompletionBindings(defaultCompletionKeymap);return Prec.highest(keymap.of([