perf(editor): fix long SQL scroll jank after select all

This commit is contained in:
zipg authored and GitHub committed 2026-10-02 23:44:28 +08:00
1 parent 92da1bcbee
commit ef16749339
6 files changed
+460 -4

No files matched your search

@@ -99,6 +99,7 @@ import { createQueryEditorSqlShortcutDomHandler, isCharacterProducingShortcut }
import { createQueryEditorReplaceShortcutBindings, createQueryEditorReplaceShortcutHandler, createQueryEditorSearchKeymap } from "@/lib/editor/queryEditorSearchKeymap";
import { createQueryEditorEscapeHandler } from "@/lib/editor/queryEditorEscape";
import { buildQueryEditorLineNumbersExtension, createQueryEditorLineNumberAlignmentExtension } from "@/lib/editor/queryEditorLineNumbers";
import { keepGuttersAttachedDuringSync } from "@/lib/editor/codemirrorGutterSync";
import { searchKeymapWithoutModD } from "@/lib/editor/codemirrorSearchKeymap";
import { defaultKeymapForGlobalShortcuts } from "@/lib/editor/codemirrorDefaultKeymap";
import { createShowWhitespaceExtension } from "@/lib/editor/codemirrorShowWhitespace";
@@ -545,7 +546,7 @@ const {
const hoverContent = createQueryEditorHoverContent({ isDark, t, toast });
const { resolveSqlHoverTooltip } = useQueryEditorHover({ props, contextMenuOpen, settingsStore, connectionStore, metadata: completionMetadata, createHoverDom: hoverContent.createHoverDom, semanticCompletionEnabled: SEMANTIC_SQL_COMPLETION_ENABLED, maxCompletionTables: MAX_COMPLETION_TABLES });
const pointerInteractions = useQueryEditorPointer({ props, clearTableNavigationHover: () => clearTableNavigationHover(), emit });
const { registerEditorScrollbarPointerGuard, registerEditorNativeSelectionDragGuard, startEditorSelectionDrag } = pointerInteractions;
const { registerEditorScrollbarPointerGuard, registerEditorNativeSelectionDragGuard, registerEditorNativeSelectionScrollGuard, startEditorSelectionDrag } = pointerInteractions;
const tableDrop = useQueryEditorTableDrop({ props, view, editorRef, settingsStore });
const { hasDroppedTableReference, insertDroppedTableReference, queryEditorDropCaret, queryEditorDropCaretStyle, showQueryEditorDropCaretAt, hideQueryEditorDropCaret, registerTableReferenceDropListener, unregisterTableReferenceDropListener } = tableDrop;
const objectNavigation = useQueryEditorObjectNavigation({
@@ -1936,6 +1937,7 @@ const codeMirrorLifecycle = useQueryEditorCodeMirror({
createQueryEditorLineNumberAlignmentExtension(ViewPlugin),
currentStatementFrameExtension,
highlightActiveLineGutter(),
keepGuttersAttachedDuringSync(ViewPlugin),
highlightSpecialChars(),
initializedRuntime.historyResetComp.of(history()),
foldGutter({
@@ -2188,6 +2190,10 @@ const codeMirrorLifecycle = useQueryEditorCodeMirror({
// such a copy happens rather than here, because that is the only moment
// the normalizer is used.
registerEditorNativeSelectionDragGuard(view.value, { finalizeClipboardText: (text) => clipboardLineEndings(text) });
// The same park, held for the length of a scroll burst: scrolling a
// long selection costs macOS 26/27 the same per-run serialization on
// every scroll event that a drag pays per pointer move.
registerEditorNativeSelectionScrollGuard(view.value, { finalizeClipboardText: (text) => clipboardLineEndings(text) });
view.value.scrollDOM.addEventListener("scroll", scheduleEditorViewportEmit, {
passive: true,
});
@@ -1,6 +1,6 @@
import type { EditorView as EditorViewType } from "@codemirror/view";
import { startsQueryEditorSelectionDrag } from "@/lib/editor/queryEditorPointerSelection";
import { keepNativeSelectionParkedDuringDrag, type EditorNativeSelectionPark } from "@/lib/editor/queryEditorNativeSelection";
import { keepNativeSelectionParkedDuringDrag, keepNativeSelectionParkedWhileScrolling, type EditorNativeSelectionPark } from "@/lib/editor/queryEditorNativeSelection";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { isMacOS } from "@/lib/backend/platform";
import type { QueryEditorProps } from "./queryEditorTypes";
@@ -27,6 +27,8 @@ export function useQueryEditorPointer(options: QueryEditorPointerOptions) {
let editorNativeSelectionParkCleanup: (() => void) | null = null;
let editorNativeSelectionScrollParkCleanup: (() => void) | null = null;
let editorSelectionDragCleanup: (() => void) | null = null;
let editorSelectionDropCursorEl: HTMLDivElement | null = null;
@@ -149,6 +151,23 @@ export function useQueryEditorPointer(options: QueryEditorPointerOptions) {
};
}
/**
* Parks the browser selection for the length of a scroll burst.
*
* Scrolling a long selection asks the macOS 26/27 web view for the same
* per-run text-services operation a drag or an open context menu does, once
* per scroll event, so a select-all document stalls and drops frames the
* whole way down. The editor keeps its own selection (CodeMirror draws it),
* so nothing about what is highlighted, copied or selected changes; see
* queryEditorNativeSelection.ts.
*/
function registerEditorNativeSelectionScrollGuard(currentView: EditorViewType, guardOptions: QueryEditorNativeSelectionDragGuardOptions = {}) {
editorNativeSelectionScrollParkCleanup?.();
editorNativeSelectionScrollParkCleanup = keepNativeSelectionParkedWhileScrolling(currentView, {
finalizeClipboardText: guardOptions.finalizeClipboardText,
});
}
function selectedRangeAtPointer(currentView: EditorViewType, event: MouseEvent) {
if (props.readOnly || event.button !== 0) return null;
if (!currentView.contentDOM.contains(event.target as Node | null)) return null;
@@ -335,8 +354,9 @@ export function useQueryEditorPointer(options: QueryEditorPointerOptions) {
function dispose() {
editorScrollbarPointerCleanup?.();
editorNativeSelectionParkCleanup?.();
editorNativeSelectionScrollParkCleanup?.();
editorSelectionDragCleanup?.();
}
return { registerEditorScrollbarPointerGuard, registerEditorNativeSelectionDragGuard, startEditorSelectionDrag, dispose };
return { registerEditorScrollbarPointerGuard, registerEditorNativeSelectionDragGuard, registerEditorNativeSelectionScrollGuard, startEditorSelectionDrag, dispose };
}