diff --git a/src/editor/core/actions.ts b/src/editor/core/actions.ts index abc9389e1..fb82ead1b 100644 --- a/src/editor/core/actions.ts +++ b/src/editor/core/actions.ts @@ -6,6 +6,7 @@ import { foldEffect, syntaxTree, toggleFold } from "@codemirror/language"; import { acceptCompletion, completionStatus } from "@codemirror/autocomplete"; import { executeAction, registerActions, type Action } from "@/platform/actions"; import { getContext } from "@/platform/context"; +import { resetSurfaceFontZoom, stepFocusedSurfaceFontZoom } from "@/workbench/contributions"; import { editorController, useGotoLine, useTabs } from "./controller"; import { addCaretsToLineEnds, @@ -109,6 +110,27 @@ function withView(run: (view: EditorView, slot: EditorSlot) => unknown) { }; } +/** Routes keyboard font zoom to focus, then the active editor slot. */ +function stepSurfaceFontSize(delta: 1 | -1): void { + const activeEl = typeof document !== "undefined" ? (document.activeElement as HTMLElement | null) : null; + if (activeEl) { + if (stepFocusedSurfaceFontZoom(delta)) return; + const cmEl = activeEl.closest?.(".cm-editor") as HTMLElement | null; + if (cmEl) { + const cmView = EditorView.findFromDOM(cmEl); + if (cmView) { + stepFontZoom(cmView, delta); + return; + } + } + } + + const slot = activeSlot(); + if (!slot?.view) return; + stepFontZoom(slot.view, delta); + if (!slot.view.hasFocus && !getContext().popupOpen) slot.view.focus(); +} + // --- extend / shrink selection --------------------------------------------------- /** One stack per selection range (by index): ⌥↑ / ⌥↓ work on every caret. */ @@ -872,6 +894,9 @@ export function registerEditorActions(): () => void { run: () => { for (const ed of useEditorRegistry.getState().editors) if (ed.view.state.field(fontZoom, false)) ed.view.dispatch({ effects: setFontZoom.of(0) }); + if (typeof document !== "undefined") { + resetSurfaceFontZoom(); + } }, }, { @@ -879,16 +904,16 @@ export function registerEditorActions(): () => void { title: "Increase Font Size", category: "View", keywords: ["zoom", "font size"], - when: EDITOR_WHEN, - run: withView((view) => stepFontZoom(view, 1)), + when: "projectOpen", + run: () => stepSurfaceFontSize(1), }, { id: "editor.decreaseFontSize", title: "Decrease Font Size", category: "View", keywords: ["zoom", "font size"], - when: EDITOR_WHEN, - run: withView((view) => stepFontZoom(view, -1)), + when: "projectOpen", + run: () => stepSurfaceFontSize(-1), }, { id: "file.toggleReadOnly", diff --git a/src/features/plugins/__tests__/webViews.test.tsx b/src/features/plugins/__tests__/webViews.test.tsx index 84338837c..2674128da 100644 --- a/src/features/plugins/__tests__/webViews.test.tsx +++ b/src/features/plugins/__tests__/webViews.test.tsx @@ -102,6 +102,31 @@ describe("web view helpers", () => { }); describe("frame bridge", () => { + it("accepts bounded zoom only from its parent with the bridge tag", () => { + const script = /