fix(editor): 避免惯性滚动误触发字号缩放
This commit is contained in:
6 files changed
+94
-7
No files matched your search
@@ -114,7 +114,7 @@ import { searchKeymapWithoutModD } from "@/lib/editor/codemirrorSearchKeymap";
|
||||
import { defaultKeymapForGlobalShortcuts } from "@/lib/editor/codemirrorDefaultKeymap";
|
||||
import { appendSqlCompletionSpace } from "@/lib/editor/sqlCompletionInsertion";
|
||||
import { compareSqlCompletions, completionLabelPresentation } from "@/lib/editor/sqlCompletionPresentation";
|
||||
import { clampEditorFontSize, createEditorZoomCommitScheduler, fontSizeFromGestureScale, fontSizeFromWheelDelta } from "@/lib/editor/editorZoom";
|
||||
import { clampEditorFontSize, createEditorWheelZoomGestureGuard, createEditorZoomCommitScheduler, fontSizeFromGestureScale, fontSizeFromWheelDelta } from "@/lib/editor/editorZoom";
|
||||
import { normalizeShortcutSettings, shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
|
||||
import { trimmedSelectionLayer } from "@/lib/editor/codemirrorTrimmedSelectionLayer";
|
||||
import { currentStatementFrameLayer } from "@/lib/editor/codemirrorCurrentStatementFrameLayer";
|
||||
@@ -699,6 +699,7 @@ const zoomCommitScheduler = createEditorZoomCommitScheduler((fontSize) => {
|
||||
if (settingsStore.editorSettings.fontSize === fontSize) return;
|
||||
settingsStore.updateEditorSettings({ fontSize });
|
||||
});
|
||||
const wheelZoomGestureGuard = createEditorWheelZoomGestureGuard();
|
||||
|
||||
const queryEditorAppearanceSettings = computed(() => {
|
||||
const settings = settingsStore.editorSettings;
|
||||
@@ -5388,7 +5389,7 @@ onMounted(async () => {
|
||||
return true;
|
||||
},
|
||||
wheel(event) {
|
||||
if (!event.metaKey && !event.ctrlKey) return false;
|
||||
if (!wheelZoomGestureGuard.accepts(event)) return false;
|
||||
event.preventDefault();
|
||||
const next = fontSizeFromWheelDelta(liveFontSize.value, event.deltaY);
|
||||
applyLiveFontSize(next);
|
||||
|
||||
@@ -49,7 +49,7 @@ import { copyToClipboard, readTextFromClipboard } from "@/lib/common/clipboard";
|
||||
import { trimmedSelectionLayer } from "@/lib/editor/codemirrorTrimmedSelectionLayer";
|
||||
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
|
||||
import { editorFontTheme, loadEditorTheme } from "@/lib/editor/editorThemes";
|
||||
import { clampEditorFontSize, createEditorZoomCommitScheduler, fontSizeFromWheelDelta } from "@/lib/editor/editorZoom";
|
||||
import { clampEditorFontSize, createEditorWheelZoomGestureGuard, createEditorZoomCommitScheduler, fontSizeFromWheelDelta } from "@/lib/editor/editorZoom";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
@@ -170,6 +170,7 @@ const configEditorZoomCommitScheduler = createEditorZoomCommitScheduler((fontSiz
|
||||
if (settingsStore.editorSettings.fontSize === fontSize) return;
|
||||
settingsStore.updateEditorSettings({ fontSize });
|
||||
});
|
||||
const configEditorWheelZoomGestureGuard = createEditorWheelZoomGestureGuard();
|
||||
const knownConfigFormats = ref<Record<string, string>>({});
|
||||
const selectedConfigKeys = ref<string[]>([]);
|
||||
const searchOpen = ref(false);
|
||||
@@ -538,7 +539,7 @@ async function mountConfigEditor() {
|
||||
keymap.of([...defaultKeymap, ...historyKeymap]),
|
||||
EditorView.domEventHandlers({
|
||||
wheel(event, eventView) {
|
||||
if (!event.metaKey && !event.ctrlKey) return false;
|
||||
if (!configEditorWheelZoomGestureGuard.accepts(event)) return false;
|
||||
event.preventDefault();
|
||||
const next = fontSizeFromWheelDelta(configEditorFontSize.value, event.deltaY);
|
||||
if (next !== configEditorFontSize.value) {
|
||||
|
||||
+2
-1
@@ -134,9 +134,10 @@ describe("NacosAdminConsole config workbench layout", () => {
|
||||
|
||||
it("keeps the configuration editor zoom behavior aligned with the SQL editor", () => {
|
||||
expect(source).toContain("createEditorZoomCommitScheduler");
|
||||
expect(source).toContain("createEditorWheelZoomGestureGuard");
|
||||
expect(source).toContain("EditorView.domEventHandlers");
|
||||
expect(source).toContain("fontSizeFromWheelDelta(configEditorFontSize.value, event.deltaY)");
|
||||
expect(source).toContain("if (!event.metaKey && !event.ctrlKey) return false;");
|
||||
expect(source).toContain("if (!configEditorWheelZoomGestureGuard.accepts(event)) return false;");
|
||||
expect(source).toContain("configEditorZoomCommitScheduler.dispose()");
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user