feat(editor): add double-click string selection mode option

This commit is contained in:
zipg authored and GitHub committed 2026-09-28 13:14:06 +08:00
1 parent 403da04d1f
commit f76cb4e46b
21 files changed
+153

No files matched your search

@@ -162,6 +162,20 @@ describe("query editor SQL string mouse selection", () => {
expect(selection && doc.slice(selection.main.from, selection.main.to)).toBe("%%");
});
it("returns null when the caller opted into plain word selection", () => {
const doc = "EXEC sp_executesql N'SELECT * FROM my_table WHERE a = 1';";
const state = EditorState.create({ doc });
const view = fakeView(state).view;
const insideString = eventAt(doc.indexOf("my_table"));
const outsideString = eventAt(doc.indexOf("sp_executesql"));
expect(createQueryEditorStringMouseSelection(view, insideString)).not.toBeNull();
expect(createQueryEditorStringMouseSelection(view, insideString, { selectStringContent: false })).toBeNull();
expect(createQueryEditorStringMouseSelection(view, outsideString, { selectStringContent: false })).toBeNull();
// Explicitly asking for the historical behaviour keeps working.
expect(createQueryEditorStringMouseSelection(view, insideString, { selectStringContent: true })).not.toBeNull();
});
it("trimSqlStringWildcardBoundaries shrinks past boundary wildcards only", () => {
const doc = "%a_b%";
expect(trimSqlStringWildcardBoundaries(doc, { from: 0, to: doc.length })).toEqual({ from: 1, to: 4 });
@@ -5,6 +5,12 @@ import { analyzeSqlSemanticSelectionRanges, sqlStringContentRangeAt, trimSqlStri
export interface QueryEditorStringMouseSelectionOptions extends SqlSemanticSelectionOptions {
language?: "sql" | "text";
composing?: boolean;
/**
* When false the double click keeps the platform default "select one word"
* behaviour instead of selecting the whole string literal. Defaults to true
* so callers that do not opt in keep the historical behaviour.
*/
selectStringContent?: boolean;
}
interface PointerPosition {
@@ -47,6 +53,7 @@ function semanticOrDefaultRange(state: EditorState, position: PointerPosition, o
}
export function createQueryEditorStringMouseSelection(view: EditorView, event: MouseEvent, options: QueryEditorStringMouseSelectionOptions = {}): MouseSelectionStyle | null {
if (options.selectStringContent === false) return null;
if (event.button !== 0 || event.detail !== 2 || event.altKey || options.composing || options.language === "text") return null;
let start = view.posAndSideAtCoords({ x: event.clientX, y: event.clientY }, false);
let analysis = analyzeSqlSemanticSelectionRanges(view.state.doc.toString(), options);
@@ -35,6 +35,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
"showWhitespace",
"ddlOpenMode",
"vimModeEnabled",
"doubleClickStringSelectionMode",
"autoCloseBrackets",
"sqlSemanticDiagnosticsMode",
"confirmDangerousSqlExecution",
@@ -142,6 +142,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =
{ id: "editor-word-wrap", category: "editor", titleKey: "settings.wordWrap", descriptionKey: "settings.wordWrapDescription", targetId: "editor" },
{ id: "editor-vim", category: "editor", titleKey: "settings.vimMode", descriptionKey: "settings.vimModeDescription", targetId: "editor" },
{ id: "editor-brackets", category: "editor", titleKey: "settings.autoCloseBrackets", descriptionKey: "settings.autoCloseBracketsDescription", targetId: "editor" },
{ id: "editor-double-click-string", category: "editor", titleKey: "settings.doubleClickStringSelectionMode", descriptionKey: "settings.doubleClickStringSelectionModeDescription", targetId: "editor" },
{ id: "editor-completion-spacing", category: "editor", titleKey: "settings.insertSpaceAfterCompletion", descriptionKey: "settings.insertSpaceAfterCompletionDescription", targetId: "editor" },
{ id: "editor-sqlserver-space-completion", category: "editor", titleKey: "settings.sqlServerSpaceConfirmsCompletion", descriptionKey: "settings.sqlServerSpaceConfirmsCompletionDescription", targetId: "editor", visible: sqlServerSpaceCompletionVisible },
{ id: "editor-completion-trigger-mode", category: "editor", titleKey: "settings.completionTriggerMode", descriptionKey: "settings.completionTriggerModeDescription", targetId: "editor" },
@@ -92,6 +92,7 @@ const SETTINGS_TRANSFER_CATEGORY_KEYS: Record<SettingsTransferCategoryId, readon
"wordWrap",
"showWhitespace",
"vimModeEnabled",
"doubleClickStringSelectionMode",
"autoCloseBrackets",
"sqlSemanticDiagnosticsMode",
"confirmDangerousSqlExecution",