25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(editor): keep long selections parked on macOS 26/27
t8y2a9ccbb0687cf
diff --git a/apps/desktop/src/lib/app/__tests__/uiTuning.spec.ts b/apps/desktop/src/lib/app/__tests__/uiTuning.spec.tsindex c47d2d5cd4..730f372c09 100644--- a/apps/desktop/src/lib/app/__tests__/uiTuning.spec.ts+++ b/apps/desktop/src/lib/app/__tests__/uiTuning.spec.ts@@ -57,6 +57,20 @@ describe("uiTuning", () => {expect(fs.readTextFile).toHaveBeenCalledWith("/home/tester/.dbx/ui-tuning.json");});+ it("parks long editor selections by default and honors the opt-out", async () => {+ fs.exists.mockResolvedValue(false);+ const { uiTuning, DEFAULT_UI_TUNING } = await loadFresh();+ expect(DEFAULT_UI_TUNING.nativeSelectionParkLongSelections).toBe(true);+ expect(uiTuning.value.nativeSelectionParkLongSelections).toBe(true);++ fs.exists.mockResolvedValue(true);+ fs.readTextFile.mockResolvedValue(JSON.stringify({ nativeSelectionParkLongSelections: false }));+ expect((await loadFresh()).uiTuning.value.nativeSelectionParkLongSelections).toBe(false);++ fs.readTextFile.mockResolvedValue(JSON.stringify({ nativeSelectionParkLongSelections: "no" }));+ expect((await loadFresh()).uiTuning.value.nativeSelectionParkLongSelections).toBe(true);+ });+it.each(["exists", "readTextFile"] as const)("keeps defaults when %s access is denied", async (command) => {fs.exists.mockResolvedValue(true);fs[command].mockRejectedValue(new Error("path not allowed"));diff --git a/apps/desktop/src/lib/app/uiTuning.ts b/apps/desktop/src/lib/app/uiTuning.tsindex 0a0ad2480c..539a1bcf7d 100644--- a/apps/desktop/src/lib/app/uiTuning.ts+++ b/apps/desktop/src/lib/app/uiTuning.ts@@ -16,10 +16,21 @@ export interface UiTuning {* tracking), 5 ≈ 12fps stepping, 10 ≈ 6fps. Clamped to 1..10.*/panelResizeTrackEveryFrames: number;+ /**+ * macOS 26/27 serializes the browser selection into an attributed string for+ * text services whenever the pointer dwells over text, at a cost that grows+ * with the number of highlighted lines. With this on, a long editor+ * selection stays parked (the browser selection is collapsed while+ * CodeMirror keeps drawing its own) for as long as it exists, including+ * after the editor loses focus. Set to `false` to only park during+ * gestures, the context menu and focused keyboard selections.+ */+ nativeSelectionParkLongSelections: boolean;}export const DEFAULT_UI_TUNING: UiTuning = {panelResizeTrackEveryFrames: 5,+ nativeSelectionParkLongSelections: true,};const MAX_TRACK_EVERY_FRAMES = 10;@@ -33,6 +44,10 @@ function sanitizeFrames(value: unknown): number {return Math.min(MAX_TRACK_EVERY_FRAMES, Math.max(1, Math.round(parsed)));}+function sanitizeParkLongSelections(value: unknown): boolean {+ return typeof value === "boolean" ? value : DEFAULT_UI_TUNING.nativeSelectionParkLongSelections;+}+let loading: Promise<void> | null = null;/** Reads `~/.dbx/ui-tuning.json` once; safe to call repeatedly. */@@ -47,6 +62,7 @@ export function loadUiTuning(): Promise<void> {const parsed = JSON.parse(await readTextFile(file)) as Partial<UiTuning>;state.value = {panelResizeTrackEveryFrames: sanitizeFrames(parsed.panelResizeTrackEveryFrames),+ nativeSelectionParkLongSelections: sanitizeParkLongSelections(parsed.nativeSelectionParkLongSelections),};console.info("[ui-tuning] loaded", file, state.value);} catch (error) {diff --git a/apps/desktop/src/lib/editor/__tests__/queryEditorNativeSelectionGuard.spec.ts b/apps/desktop/src/lib/editor/__tests__/queryEditorNativeSelectionGuard.spec.tsindex 6846fd0e96..6d04a08c23 100644--- a/apps/desktop/src/lib/editor/__tests__/queryEditorNativeSelectionGuard.spec.ts+++ b/apps/desktop/src/lib/editor/__tests__/queryEditorNativeSelectionGuard.spec.ts@@ -25,7 +25,7 @@ beforeEach(() => {});});-function createView(options: { enabled?: boolean; readOnly?: boolean } = {}) {+function createView(options: { enabled?: boolean; readOnly?: boolean; parkLongSelections?: boolean } = {}) {const execute = vi.fn((view: EditorView) => {view.focus();return view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to);@@ -39,7 +39,12 @@ function createView(options: { enabled?: boolean; readOnly?: boolean } = {}) {history(),EditorState.readOnly.of(options.readOnly ?? false),EditorView.clipboardOutputFilter.of((text) => text.replaceAll("\n", "\r\n")),- createQueryEditorNativeSelectionGuard(ViewPlugin, { enabled: options.enabled ?? true, inputHandler: EditorView.inputHandler, finalizeClipboardText: (text) => text.replaceAll("\n", "\r\n") }),+ createQueryEditorNativeSelectionGuard(ViewPlugin, {+ enabled: options.enabled ?? true,+ inputHandler: EditorView.inputHandler,+ finalizeClipboardText: (text) => text.replaceAll("\n", "\r\n"),+ parkLongSelections: options.parkLongSelections,+ }),keymap.of([{ key: "Meta-a", run: selectAll }, { key: "Meta-Enter", run: (currentView) => !!execute(currentView) }, ...defaultKeymap]),],}),@@ -49,6 +54,36 @@ function createView(options: { enabled?: boolean; readOnly?: boolean } = {}) {return { view, execute };}+/**+ * Drives animation frames by hand. The guard's park keeps itself alive with a+ * `requestAnimationFrame` loop, and happy-dom never lets an awaited timer run+ * while that loop is queued — so a test that needs a frame flushes it here.+ */+function useManualFrames() {+ let handle = 0;+ const pending = new Map<number, FrameRequestCallback>();+ vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {+ handle += 1;+ pending.set(handle, callback);+ return handle;+ });+ vi.stubGlobal("cancelAnimationFrame", (cancelled: number) => {+ pending.delete(cancelled);+ });+ return (frames = 2) => {+ for (let index = 0; index < frames; index += 1) {+ const batch = [...pending.values()];+ pending.clear();+ for (const callback of batch) callback(performance.now());+ }+ };+}++function holdsSelectionWriteSuppression(view: EditorView) {+ const internals = view as unknown as { docView: object };+ return Object.prototype.hasOwnProperty.call(internals.docView, "updateSelection");+}+function press(view: EditorView, key: string, options: KeyboardEventInit = {}) {const event = new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...options });view.contentDOM.dispatchEvent(event);@@ -72,6 +107,7 @@ function expectParked(view: EditorView) {afterEach(() => {for (const view of views.splice(0)) view.destroy();document.body.replaceChildren();+ vi.unstubAllGlobals();vi.restoreAllMocks();});@@ -264,4 +300,40 @@ describe("macOS long native selection guard", () => {view.destroy();expect(document.getSelection()?.toString()).toBe("Other editor");});++ it("holds the parked selection after the editor loses focus", () => {+ const runFrames = useManualFrames();+ const { view } = createView();+ selectAll(view);+ expectParked(view);++ const other = document.body.appendChild(document.createElement("input"));+ other.focus();+ view.dispatch({ selection: view.state.selection });+ runFrames();+ expectParked(view);+ expect(holdsSelectionWriteSuppression(view)).toBe(true);+ });++ it("does not steal a selection made outside the editor while parked", () => {+ const runFrames = useManualFrames();+ const { view } = createView();+ selectAll(view);+ const other = document.body.appendChild(document.createElement("div"));+ other.textContent = "grid text";+ // Focus stays in the editor; another panel claims the browser selection.+ document.getSelection()!.selectAllChildren(other);+ runFrames();+ expect(document.getSelection()?.toString()).toBe("grid text");+ expect(holdsSelectionWriteSuppression(view)).toBe(true);+ });++ it("drops the park on blur when the long-selection hold is switched off", () => {+ const { view } = createView({ parkLongSelections: false });+ selectAll(view);+ expect(holdsSelectionWriteSuppression(view)).toBe(true);+ const other = document.body.appendChild(document.createElement("input"));+ other.focus();+ expect(holdsSelectionWriteSuppression(view)).toBe(false);+ });});diff --git a/apps/desktop/src/lib/editor/queryEditorNativeSelection.ts b/apps/desktop/src/lib/editor/queryEditorNativeSelection.tsindex 351ea8b042..234a2130a1 100644--- a/apps/desktop/src/lib/editor/queryEditorNativeSelection.ts+++ b/apps/desktop/src/lib/editor/queryEditorNativeSelection.ts@@ -1,4 +1,5 @@import type { EditorView, ViewPlugin, ViewUpdate } from "@codemirror/view";+import { uiTuning } from "@/lib/app/uiTuning";import { appendDebugLog } from "@/lib/backend/debugLog";/**@@ -12,16 +13,23 @@ import { appendDebugLog } from "@/lib/backend/debugLog";* thread and makes right click, Esc and the whole window feel frozen.** The browser selection does not have to cover the selection for the editor to- * behave: CodeMirror paints the selection itself (`drawSelection` keeps the- * native one transparent), it copies from its own state, and it ignores a- * selection parked outside its content element. So the browser selection is- * parked on the editor chrome while an overlay menu covers the editor, and for- * as long as a pointer gesture is dragging a long selection out, and restored- * as soon as the menu closes or the pointer is released. On macOS desktop a- * view plugin also holds long keyboard selections, including during execution.- * Its collapsed caret stays inside the editable so native input without a- * keydown still arrives. The observer cache is updated together with that caret- * so CodeMirror does not mistake the parked position for a user selection.+ * behave: CodeMirror paints the selection itself (`trimmedSelectionLayer`, and+ * `drawSelection` keeps the native one transparent), it copies from its own+ * state, and it ignores a selection parked outside its content element. So the+ * browser selection is parked on the editor chrome while an overlay menu covers+ * the editor, for as long as a pointer gesture is dragging a long selection+ * out, and restored as soon as the menu closes or the pointer is released. On+ * macOS desktop a view plugin also holds any long selection for as long as it+ * exists, focused or not: a parked selection that survives focus loss cannot be+ * published again by a focus repair or by CodeMirror's next write, which is what+ * kept long documents stuttering with third-party fonts installed. Its+ * collapsed caret stays inside the editable so native input without a keydown+ * still arrives. The observer cache is updated together with that caret so+ * CodeMirror does not mistake the parked position for a user selection.+ *+ * A park never collapses a selection that already belongs to another element,+ * so a long editor selection can stay parked while the user selects text in the+ * grid, a chat, or a settings field.** The drag is the case that is easiest to misread from a bug report: sweeping* the pointer to the edge of the editor autoscrolls and never leaves the@@ -320,7 +328,11 @@ function createNativeSelectionPark(currentView: EditorView, config: NativeSelectconst park = () => {if (released || !shouldKeepParked()) return;const selection = editorRootSelection(currentView);- if (!selection || (!currentView.hasFocus && (!selection.anchorNode || !currentView.dom.contains(selection.anchorNode)))) return;+ // Only ever collapse a selection that already belongs to the editor. A park+ // can outlive focus now, and the user may be selecting text in the grid or+ // a chat while it is held: re-collapsing there would steal that selection+ // every frame.+ if (!selection || !selection.anchorNode || !currentView.dom.contains(selection.anchorNode)) return;if (suppressWrites && !restoreWrites) restoreWrites = suppressEditorSelectionWrites(currentView);if (insideContent && !restoreWrites) return;const parkInsideContent = insideContent && parks.outside === 0;@@ -521,8 +533,21 @@ export function keepNativeSelectionParkedDuringDrag(currentView: EditorView, opt});}-export function createQueryEditorNativeSelectionGuard(plugin: typeof ViewPlugin, options: EditorNativeSelectionParkOptions & { enabled: boolean; inputHandler: typeof EditorView.inputHandler }) {+export function createQueryEditorNativeSelectionGuard(+ plugin: typeof ViewPlugin,+ options: EditorNativeSelectionParkOptions & {+ enabled: boolean;+ inputHandler: typeof EditorView.inputHandler;+ /**+ * Hold a long selection parked for as long as it exists instead of only+ * while the editor has focus. Defaults to the `uiTuning` dial; pass an+ * explicit value in tests.+ */+ parkLongSelections?: boolean;+ },+) {if (!options.enabled) return [];+ const parkLongSelections = options.parkLongSelections ?? uiTuning.value.nativeSelectionParkLongSelections;return plugin.fromClass(class {private park: EditorNativeSelectionPark | null = null;@@ -548,7 +573,21 @@ export function createQueryEditorNativeSelectionGuard(plugin: typeof ViewPlugin,this.sync();}- private canPark = () => this.currentView.hasFocus && !this.nativeInputPending && !this.composing && !this.currentView.compositionStarted && isLargeEditorSelection(this.currentView);+ private browserSelectionInsideEditor() {+ const selection = editorRootSelection(this.currentView);+ const anchor = selection?.anchorNode ?? null;+ return !!anchor && this.currentView.dom.contains(anchor);+ }++ private canPark = () => {+ if (this.nativeInputPending || this.composing || this.currentView.compositionStarted) return false;+ if (!isLargeEditorSelection(this.currentView)) return false;+ if (!parkLongSelections) return this.currentView.hasFocus;+ // A parked caret already lives in the editor chrome, so an unfocused+ // editor still owns the browser selection as long as nothing else+ // claimed it (see the ownership check in `createNativeSelectionPark`).+ return this.currentView.hasFocus || this.browserSelectionInsideEditor();+ };private sync() {if (!this.canPark() || !canGuardNativeSelection(this.currentView)) {@@ -620,7 +659,24 @@ export function createQueryEditorNativeSelectionGuard(plugin: typeof ViewPlugin,private onBlur = () => {this.nativeInputPending = false;- this.release(false);+ // Keep a long selection parked after focus leaves: the park already+ // left a collapsed caret behind, and releasing here is what let a focus+ // repair or the next CodeMirror write publish the full range again —+ // the macOS 26/27 serialization cost scales with that range, so a+ // third-party font turned it into a multi-second stall. Short+ // selections and the `uiTuning` kill switch still hand it back.+ if (!parkLongSelections) {+ this.release(false);+ return;+ }+ this.sync();+ // Field diagnosis for a report of "selecting then executing stalls":+ // this line shows whether a long selection was still parked after the+ // click moved focus to the execute button.+ if (this.park) {+ const main = this.currentView.state.selection.main;+ appendDebugLog("info", "[DBX][QueryEditor:native-selection:hold]", { chars: main.to - main.from });+ }};private onFocus = () => {