Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(editor): avoid extra cursor in column selection

t8y2f7f0397407c9
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index db43b8ee35..3de4851bba 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -57,6 +57,7 @@ import { normalizeShortcutSettings, shortcutToCodeMirrorKey } from "@/lib/editor
import { trimmedSelectionLayer } from "@/lib/editor/codemirrorTrimmedSelectionLayer";
import { selectionMatchOccurrences } from "@/lib/editor/codemirrorSelectionMatches";
import { createDbxCodeMirrorSqlDialect } from "@/lib/editor/codemirrorSqlDialect";
+import { startsQueryEditorRectangularSelection } from "@/lib/editor/queryEditorPointerSelection";
import { isSchemaAware, isSingleDatabase, supportsSqlInListPaste } from "@/lib/database/databaseFeatureSupport";
import { usesLocalOnlyEditorCompletionMetadata, usesOnDemandOnlyEditorColumnMetadata } from "@/lib/metadata/completionMetadataPolicy";
import { qualifiedTableNameAtSqlPosition } from "@/lib/sql/queryCursorTableTarget";
@@ -2789,7 +2790,6 @@ onMounted(async () => {
dropCursor(),
EditorView.dragMovesSelection.of((event) => !event.ctrlKey && !event.metaKey),
EditorState.allowMultipleSelections.of(true),
- EditorView.clickAddsSelectionRange.of((event) => event.altKey && event.button === 0),
indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
crosshairCursor(),
@@ -2824,7 +2824,9 @@ onMounted(async () => {
wordWrapComp.of(props.forceWordWrap || initialSettings.wordWrap ? EditorView.lineWrapping : []),
readOnlyComp.of([EditorState.readOnly.of(!!props.readOnly), EditorView.editable.of(!props.readOnly)]),
indentComp.of(indentExtension()),
- rectangularSelection({ eventFilter: (e: MouseEvent) => e.altKey || e.button === 1 }),
+ // Alt+drag belongs exclusively to rectangular selection. Registering the
+ // same gesture as an added cursor preserves the previous cursor.
+ rectangularSelection({ eventFilter: startsQueryEditorRectangularSelection }),
EditorView.updateListener.of((update) => {
if (update.docChanged) {
searchPanelRef.value?.scheduleDocumentSearchUpdate();
diff --git a/apps/desktop/src/lib/__tests__/editor/queryEditorPointerSelection.spec.ts b/apps/desktop/src/lib/__tests__/editor/queryEditorPointerSelection.spec.ts
new file mode 100644
index 0000000000..da263ec3f3
--- /dev/null
+++ b/apps/desktop/src/lib/__tests__/editor/queryEditorPointerSelection.spec.ts
@@ -0,0 +1,16 @@
+import { describe, expect, it } from "vitest";
+import { startsQueryEditorRectangularSelection } from "@/lib/editor/queryEditorPointerSelection";
+
+describe("query editor pointer selection", () => {
+ it("starts rectangular selection for Alt+left drag", () => {
+ expect(startsQueryEditorRectangularSelection({ altKey: true, button: 0 })).toBe(true);
+ });
+
+ it("starts rectangular selection for middle-button drag", () => {
+ expect(startsQueryEditorRectangularSelection({ altKey: false, button: 1 })).toBe(true);
+ });
+
+ it("leaves ordinary left clicks to the normal cursor handler", () => {
+ expect(startsQueryEditorRectangularSelection({ altKey: false, button: 0 })).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/lib/editor/queryEditorPointerSelection.ts b/apps/desktop/src/lib/editor/queryEditorPointerSelection.ts
new file mode 100644
index 0000000000..bcc545f909
--- /dev/null
+++ b/apps/desktop/src/lib/editor/queryEditorPointerSelection.ts
@@ -0,0 +1,8 @@
+export interface QueryEditorPointerEvent {
+ altKey: boolean;
+ button: number;
+}
+
+export function startsQueryEditorRectangularSelection(event: QueryEditorPointerEvent): boolean {
+ return event.altKey || event.button === 1;
+}