дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
feat(markdown): zoom the focused preview with Cmd/Ctrl+= and Cmd/Ctrl+- (#7523)
With the Markdown preview focused, the editor's expand / collapse keys (Cmd/Ctrl+= and Cmd/Ctrl+-) run the new Increase / Decrease Preview Font Size actions, gated by a markdownPreviewFocus context key; in the editor they still expand and collapse folds. The Eclipse keymaps already give these keys to Increase / Decrease Font Size, which zooms the focused preview, so they leave the new actions unbound. Fixes #7380
Цей коміт міститься в:
1 джерело
2221afad01
коміт
1dd8ea9b3b
12 files changed
+99
-4
No files matched your search
@@ -44,6 +44,7 @@ import { registerRstLiveSource } from "./rst/live";
|
||||
import { rstModes, RstLayoutActions } from "./rst/RstLayoutActions";
|
||||
import { SvgLayoutActions, svgModes } from "./svg/SvgEditor";
|
||||
import { MarkdownLayoutActions } from "./markdown/MarkdownLayoutActions";
|
||||
import { markdownPreviewFontActions } from "./markdown/previewFontActions";
|
||||
import { canExtractImages, extractImages, EXTRACT_IMAGES, EXTRACT_IMAGES_TITLE } from "./markdown/extractImages";
|
||||
|
||||
const titleOf = (input: EditorInput) => basename(input.path ?? input.key);
|
||||
@@ -197,7 +198,7 @@ export function activate(): () => void {
|
||||
items: (_menu, { paths: [path] }) =>
|
||||
path === activeEditor()?.ctx.path && canExtractImages() ? [{ kind: "action", action: EXTRACT_IMAGES }] : [],
|
||||
}),
|
||||
registerActions([...imageActions(), ...markdownActions()]),
|
||||
registerActions([...imageActions(), ...markdownActions(), ...markdownPreviewFontActions()]),
|
||||
];
|
||||
return () => disposers.reverse().forEach((d) => d());
|
||||
}
|
||||
@@ -94,6 +94,7 @@ import { writeClipboardText } from "@/platform/clipboard";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { isVirtualUri } from "@/platform/virtualDocs";
|
||||
import { wheelZoomStep } from "@/platform/wheelZoom";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { iconNode } from "@/ui/iconNode";
|
||||
import { create } from "zustand";
|
||||
import { isMarkdownPath, isMdxPath } from "../fileKinds";
|
||||
@@ -1360,6 +1361,8 @@ function MarkdownPreview({
|
||||
root.removeEventListener("wheel", onWheel, { capture: true });
|
||||
root.removeEventListener("wheel", onPreviewWheel);
|
||||
release();
|
||||
const focused = document.activeElement;
|
||||
if (!focused || focused === document.body || root.contains(focused)) setContext("markdownPreviewFocus", false);
|
||||
};
|
||||
}, [path]);
|
||||
|
||||
@@ -1442,6 +1445,10 @@ function MarkdownPreview({
|
||||
tabIndex={-1}
|
||||
role="document"
|
||||
aria-label={tx("Markdown preview")}
|
||||
onFocus={() => setContext("markdownPreviewFocus", true)}
|
||||
onBlur={(e) => {
|
||||
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setContext("markdownPreviewFocus", false);
|
||||
}}
|
||||
onClick={onClick}
|
||||
onScroll={onScroll}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { Action } from "@/platform/actions";
|
||||
import { stepFocusedSurfaceFontZoom } from "@/workbench/contributions";
|
||||
|
||||
/**
|
||||
* Increase / Decrease Preview Font Size: the focused Markdown preview takes the zoom keys
|
||||
* (⌘/Ctrl+= and ⌘/Ctrl+-) that expand and collapse folds in the editor, as in IntelliJ IDEA.
|
||||
*/
|
||||
export function markdownPreviewFontActions(): Action[] {
|
||||
const action = (id: string, title: string, delta: number): Action => ({
|
||||
id,
|
||||
title,
|
||||
category: "Markdown",
|
||||
keywords: ["zoom", "font size"],
|
||||
when: "markdownPreviewFocus",
|
||||
keyWhen: "markdownPreviewFocus",
|
||||
run: () => void stepFocusedSurfaceFontZoom(delta),
|
||||
});
|
||||
return [
|
||||
action("markdown.preview.increaseFontSize", "Increase Preview Font Size", 1),
|
||||
action("markdown.preview.decreaseFontSize", "Decrease Preview Font Size", -1),
|
||||
];
|
||||
}
|
||||
@@ -13,7 +13,8 @@ import {
|
||||
import { fontZoom, resetAllEditorsFontZoom, setFontZoom } from "@/editor/core/cm/prefs";
|
||||
import { fontExtension } from "@/editor/core/cm/setup";
|
||||
import type { EditorSlot } from "@/editor/core/model/slot";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { executeAction, registerActions } from "@/platform/actions";
|
||||
import { applyKeymapSettings, installKeyboardDispatcher } from "@/platform/keymap";
|
||||
import { useContextKeys } from "@/platform/context";
|
||||
import { intellijMacos } from "@/platform/keymaps/intellij-macos";
|
||||
import { intellijWindows } from "@/platform/keymaps/intellij-windows";
|
||||
@@ -37,6 +38,7 @@ const { registerEditorActions } = await import("@/editor/core/actions");
|
||||
const { registerMarkdownLiveSource, useLiveMarkdown } = await import("./live");
|
||||
const { MarkdownEditor } = await import("./MarkdownEditor");
|
||||
const { useMarkdownModes } = await import("./modes");
|
||||
const { markdownPreviewFontActions } = await import("./previewFontActions");
|
||||
|
||||
const mdCtx: EditorDocContext = { doc: 1, path: "/p/README.md", language: "markdown", uiMode: null, readOnly: false };
|
||||
const tsCtx: EditorDocContext = { doc: 2, path: "/p/a.ts", language: "typescript", uiMode: null, readOnly: false };
|
||||
@@ -244,6 +246,51 @@ describe("editor font size actions", () => {
|
||||
expect(preview.style.getPropertyValue("--markdown-zoom-scale")).toBe("1");
|
||||
});
|
||||
|
||||
it("takes ⌘/Ctrl+= and ⌘/Ctrl+- in the focused preview, leaving them to fold in the editor (#7380)", async () => {
|
||||
const md = open(mdCtx);
|
||||
activate(md);
|
||||
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "split" } })));
|
||||
render(
|
||||
<MarkdownEditor path={mdCtx.path} tabId="t">
|
||||
<div />
|
||||
</MarkdownEditor>,
|
||||
);
|
||||
disposers.push(registerActions(markdownPreviewFontActions()));
|
||||
const unfold = vi.fn();
|
||||
const fold = vi.fn();
|
||||
disposers.push(
|
||||
registerActions([
|
||||
{ id: "code.unfold", title: "Expand", keyWhen: "editorFocus", run: unfold },
|
||||
{ id: "code.fold", title: "Collapse", keyWhen: "editorFocus", run: fold },
|
||||
]),
|
||||
);
|
||||
disposers.push(installKeyboardDispatcher(window));
|
||||
const press = async (preset: string, key: string, mod: "metaKey" | "ctrlKey") => {
|
||||
applyKeymapSettings(preset, {});
|
||||
document.activeElement!.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key, code: key === "=" ? "Equal" : "Minus", [mod]: true, bubbles: true }),
|
||||
);
|
||||
await act(() => Promise.resolve());
|
||||
};
|
||||
const preview = screen.getByRole("document", { name: "Markdown preview" });
|
||||
|
||||
act(() => preview.focus());
|
||||
await press("intellij-macos", "=", "metaKey");
|
||||
await press("intellij-windows", "=", "ctrlKey");
|
||||
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("2px");
|
||||
await press("intellij-macos", "-", "metaKey");
|
||||
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("1px");
|
||||
expect(unfold).not.toHaveBeenCalled();
|
||||
expect(fold).not.toHaveBeenCalled();
|
||||
|
||||
act(() => preview.blur());
|
||||
expect(useContextKeys.getState().markdownPreviewFocus).toBe(false);
|
||||
act(() => md.contentDOM.focus());
|
||||
await press("intellij-windows", "=", "ctrlKey");
|
||||
expect(unfold).toHaveBeenCalledOnce();
|
||||
expect(preview.style.getPropertyValue("--markdown-font-zoom")).toBe("1px");
|
||||
});
|
||||
|
||||
it("sizes embedded excalidraw.svg, graph SVGs and raster images so they scale with font zoom", async () => {
|
||||
const box = (img: HTMLImageElement) => img.closest<HTMLElement>(".image-zoom")!;
|
||||
const excalidrawSvg =
|
||||
|
||||
@@ -174,5 +174,8 @@ export const eclipseMacos: Record<string, string[]> = {
|
||||
"toolwindow.resizeUp": [],
|
||||
"toolwindow.resizeDown": [],
|
||||
"editor.decreaseFontSize": ["Meta+-"],
|
||||
// Increase / Decrease Font Size already take these keys, and zoom the focused Markdown preview.
|
||||
"markdown.preview.increaseFontSize": [],
|
||||
"markdown.preview.decreaseFontSize": [],
|
||||
"editor.increaseFontSize": ["Meta+="],
|
||||
};
|
||||
@@ -178,5 +178,8 @@ export const eclipseWindows: Record<string, string[]> = {
|
||||
"toolwindow.resizeUp": [],
|
||||
"toolwindow.resizeDown": [],
|
||||
"editor.decreaseFontSize": ["Ctrl+-"],
|
||||
// Increase / Decrease Font Size already take these keys, and zoom the focused Markdown preview.
|
||||
"markdown.preview.increaseFontSize": [],
|
||||
"markdown.preview.decreaseFontSize": [],
|
||||
"editor.increaseFontSize": ["Ctrl+="],
|
||||
};
|
||||
@@ -455,6 +455,8 @@ export const intellijMacos: Record<string, string[]> = {
|
||||
"code.expressionTypeInfo": ["Ctrl+Shift+P"],
|
||||
"code.implementMethods": ["Ctrl+I"],
|
||||
"code.overrideMethods": ["Ctrl+O"],
|
||||
"markdown.preview.increaseFontSize": ["Meta+="],
|
||||
"markdown.preview.decreaseFontSize": ["Meta+-"],
|
||||
"image.zoomIn": ["Meta+="],
|
||||
"image.zoomOut": ["Meta+-"],
|
||||
"image.actualSize": ["Meta+/"],
|
||||
|
||||
@@ -453,6 +453,8 @@ export const intellijWindows: Record<string, string[]> = {
|
||||
"code.expressionTypeInfo": ["Ctrl+Shift+P"],
|
||||
"code.implementMethods": ["Ctrl+I"],
|
||||
"code.overrideMethods": ["Ctrl+O"],
|
||||
"markdown.preview.increaseFontSize": ["Ctrl+="],
|
||||
"markdown.preview.decreaseFontSize": ["Ctrl+-"],
|
||||
"image.zoomIn": ["Ctrl+="],
|
||||
"image.zoomOut": ["Ctrl+-"],
|
||||
"image.actualSize": ["Ctrl+/"],
|
||||
|
||||
@@ -458,6 +458,8 @@ export const vscodeMacos: Record<string, string[]> = {
|
||||
"code.expressionTypeInfo": [],
|
||||
"code.implementMethods": [],
|
||||
"code.overrideMethods": [],
|
||||
"markdown.preview.increaseFontSize": [],
|
||||
"markdown.preview.decreaseFontSize": [],
|
||||
"image.zoomIn": [],
|
||||
"image.zoomOut": [],
|
||||
"image.actualSize": [],
|
||||
|
||||
@@ -57,6 +57,8 @@ export const vscodeWindows: Record<string, string[]> = {
|
||||
"code.expressionTypeInfo": [],
|
||||
"code.implementMethods": [],
|
||||
"code.overrideMethods": [],
|
||||
"markdown.preview.increaseFontSize": [],
|
||||
"markdown.preview.decreaseFontSize": [],
|
||||
"image.zoomIn": [],
|
||||
"image.zoomOut": [],
|
||||
"image.actualSize": [],
|
||||
|
||||
@@ -5154,5 +5154,7 @@
|
||||
"Until an Xcode project's first build, sourcekit-lsp can't resolve types from its other targets. Builds what Run builds, at low priority, once.": "Until an Xcode project's first build, sourcekit-lsp can't resolve types from its other targets. Builds what Run builds, at low priority, once.",
|
||||
"Code insight for {container} reads its last build. Without one yet, it is built in the background.": "Code insight for {container} reads its last build. Without one yet, it is built in the background.",
|
||||
"Background build for code insight failed": "Background build for code insight failed",
|
||||
"Code insight reads what it built. Run shows the whole build log.": "Code insight reads what it built. Run shows the whole build log."
|
||||
"Code insight reads what it built. Run shows the whole build log.": "Code insight reads what it built. Run shows the whole build log.",
|
||||
"Increase Preview Font Size": "Increase Preview Font Size",
|
||||
"Decrease Preview Font Size": "Decrease Preview Font Size"
|
||||
}
|
||||
@@ -12034,5 +12034,7 @@
|
||||
"Language server updates are available": "语言服务器有可用更新",
|
||||
"Vue Language Server version": "Vue 语言服务器版本",
|
||||
"Auto uses 3.0.x for Vue 2 projects and the latest release for Vue 3.": "自动选择时,Vue 2 项目使用 3.0.x,Vue 3 项目使用最新版本。",
|
||||
"Enter latest, 3.0.x, or an exact Vue Language Server version.": "请输入 latest、3.0.x 或 Vue 语言服务器的具体版本。"
|
||||
"Enter latest, 3.0.x, or an exact Vue Language Server version.": "请输入 latest、3.0.x 或 Vue 语言服务器的具体版本。",
|
||||
"Increase Preview Font Size": "增大预览字体",
|
||||
"Decrease Preview Font Size": "减小预览字体"
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача