fix(editor): preserve multi-cursor clicks on identifiers
This commit is contained in:
3 files changed
+33
-8
No files matched your search
@@ -87,7 +87,7 @@ import { createInsertValueHintsExtension, requestInsertValueHintsRefresh } from
|
|||||||
import { focusEditorView } from "@/lib/editor/queryEditorFocus";
|
import { focusEditorView } from "@/lib/editor/queryEditorFocus";
|
||||||
import { createDbxCodeMirrorSqlDialect, type CodeMirrorSqlDialectName } from "@/lib/editor/codemirrorSqlDialect";
|
import { createDbxCodeMirrorSqlDialect, type CodeMirrorSqlDialectName } from "@/lib/editor/codemirrorSqlDialect";
|
||||||
import { sqlSemanticTableNameSpansForSyntaxTree } from "@/lib/editor/codemirrorSqlSemanticHighlight";
|
import { sqlSemanticTableNameSpansForSyntaxTree } from "@/lib/editor/codemirrorSqlSemanticHighlight";
|
||||||
import { startsQueryEditorRectangularSelection } from "@/lib/editor/queryEditorPointerSelection";
|
import { startsQueryEditorRectangularSelection, usesQueryEditorObjectNavigationModifier } from "@/lib/editor/queryEditorPointerSelection";
|
||||||
import { LARGE_PASTE_HISTORY_USER_EVENT, normalizeQueryEditorPasteText, recoverableNativePasteSuffix, shouldRecoverLargeTauriPaste } from "@/lib/editor/queryEditorLargePaste";
|
import { LARGE_PASTE_HISTORY_USER_EVENT, normalizeQueryEditorPasteText, recoverableNativePasteSuffix, shouldRecoverLargeTauriPaste } from "@/lib/editor/queryEditorLargePaste";
|
||||||
import type { StatementExecutionMarker } from "@/lib/tabs/tabPresentation";
|
import type { StatementExecutionMarker } from "@/lib/tabs/tabPresentation";
|
||||||
import { isSchemaAware, isSingleDatabase, supportsDatabaseNameCompletion, supportsDatabaseSchemaQualifier, supportsSqlInListPaste } from "@/lib/database/databaseFeatureSupport";
|
import { isSchemaAware, isSingleDatabase, supportsDatabaseNameCompletion, supportsDatabaseSchemaQualifier, supportsSqlInListPaste } from "@/lib/database/databaseFeatureSupport";
|
||||||
@@ -845,7 +845,7 @@ function tableNavigationIdentifierAt(currentView: EditorViewType, event: MouseEv
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateTableNavigationHover(currentView: EditorViewType, event: MouseEvent) {
|
function updateTableNavigationHover(currentView: EditorViewType, event: MouseEvent) {
|
||||||
if (!event.metaKey && !event.ctrlKey) {
|
if (!usesQueryEditorObjectNavigationModifier(event)) {
|
||||||
clearTableNavigationHover();
|
clearTableNavigationHover();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -855,7 +855,7 @@ function updateTableNavigationHover(currentView: EditorViewType, event: MouseEve
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearTableNavigationHoverOnModifierRelease(event: KeyboardEvent) {
|
function clearTableNavigationHoverOnModifierRelease(event: KeyboardEvent) {
|
||||||
if (!event.metaKey && !event.ctrlKey) clearTableNavigationHover();
|
if (!usesQueryEditorObjectNavigationModifier(event)) clearTableNavigationHover();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEditorScrollbarPointerEvent(currentView: EditorViewType, event: MouseEvent) {
|
function isEditorScrollbarPointerEvent(currentView: EditorViewType, event: MouseEvent) {
|
||||||
@@ -4219,14 +4219,15 @@ onMounted(async () => {
|
|||||||
if (currentView && startEditorSelectionDrag(currentView, event)) {
|
if (currentView && startEditorSelectionDrag(currentView, event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Click without modifier -> close column panel
|
// Alt belongs to CodeMirror's rectangular and multi-cursor gestures,
|
||||||
if (!event.metaKey && !event.ctrlKey) {
|
// even when Cmd/Ctrl is held at the same time.
|
||||||
if (event.button === 0) {
|
if (!usesQueryEditorObjectNavigationModifier(event)) {
|
||||||
|
// Click without modifier -> close column panel
|
||||||
|
if (!event.metaKey && !event.ctrlKey && event.button === 0) {
|
||||||
emit("closeColumnPanel");
|
emit("closeColumnPanel");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Only handle Ctrl/Cmd + left click
|
|
||||||
if (event.button !== 0) return false;
|
if (event.button !== 0) return false;
|
||||||
|
|
||||||
if (!currentView || !props.connectionId || props.database == null) {
|
if (!currentView || !props.connectionId || props.database == null) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { startsQueryEditorRectangularSelection } from "@/lib/editor/queryEditorPointerSelection";
|
import { startsQueryEditorRectangularSelection, usesQueryEditorObjectNavigationModifier } from "@/lib/editor/queryEditorPointerSelection";
|
||||||
|
|
||||||
describe("query editor pointer selection", () => {
|
describe("query editor pointer selection", () => {
|
||||||
it("starts rectangular selection for Alt+left drag", () => {
|
it("starts rectangular selection for Alt+left drag", () => {
|
||||||
@@ -13,4 +13,18 @@ describe("query editor pointer selection", () => {
|
|||||||
it("leaves ordinary left clicks to the normal cursor handler", () => {
|
it("leaves ordinary left clicks to the normal cursor handler", () => {
|
||||||
expect(startsQueryEditorRectangularSelection({ altKey: false, button: 0 })).toBe(false);
|
expect(startsQueryEditorRectangularSelection({ altKey: false, button: 0 })).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses Cmd or Ctrl without Alt for object navigation", () => {
|
||||||
|
expect(usesQueryEditorObjectNavigationModifier({ altKey: false, ctrlKey: false, metaKey: true })).toBe(true);
|
||||||
|
expect(usesQueryEditorObjectNavigationModifier({ altKey: false, ctrlKey: true, metaKey: false })).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("leaves Alt+Cmd and Alt+Ctrl to multi-cursor selection", () => {
|
||||||
|
expect(usesQueryEditorObjectNavigationModifier({ altKey: true, ctrlKey: false, metaKey: true })).toBe(false);
|
||||||
|
expect(usesQueryEditorObjectNavigationModifier({ altKey: true, ctrlKey: true, metaKey: false })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not treat an unmodified pointer event as object navigation", () => {
|
||||||
|
expect(usesQueryEditorObjectNavigationModifier({ altKey: false, ctrlKey: false, metaKey: false })).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -3,6 +3,16 @@ export interface QueryEditorPointerEvent {
|
|||||||
button: number;
|
button: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface QueryEditorObjectNavigationModifierEvent {
|
||||||
|
altKey: boolean;
|
||||||
|
ctrlKey: boolean;
|
||||||
|
metaKey: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export function startsQueryEditorRectangularSelection(event: QueryEditorPointerEvent): boolean {
|
export function startsQueryEditorRectangularSelection(event: QueryEditorPointerEvent): boolean {
|
||||||
return event.altKey || event.button === 1;
|
return event.altKey || event.button === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function usesQueryEditorObjectNavigationModifier(event: QueryEditorObjectNavigationModifierEvent): boolean {
|
||||||
|
return !event.altKey && (event.metaKey || event.ctrlKey);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user