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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(editor): add query editing utilities
JeaceLiu782615586ceb
diff --git a/.gitignore b/.gitignoreindex 880af71ae4..e9c502dbc4 100644--- a/.gitignore+++ b/.gitignore@@ -63,4 +63,4 @@ DBX_*_x64-portable.zip.agents/skills.pnpm-store/*.dbx-web-_dev+.npmrcdiff --git a/apps/desktop/src/components/editor/DelimitedListDialog.vue b/apps/desktop/src/components/editor/DelimitedListDialog.vuenew file mode 100644index 0000000000..022a11fe2c--- /dev/null+++ b/apps/desktop/src/components/editor/DelimitedListDialog.vue@@ -0,0 +1,206 @@+<script setup lang="ts">+import { computed, ref, watch } from "vue";+import { useI18n } from "vue-i18n";+import { List, Copy } from "@lucide/vue";+import { Button } from "@/components/ui/button";+import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import { useToast } from "@/composables/useToast";+import { copyToClipboard } from "@/lib/common/clipboard";++const { t } = useI18n();+const { toast } = useToast();++const open = defineModel<boolean>("open", { default: false });++const props = defineProps<{+ selectedText: string;+}>();++const emit = defineEmits<{+ confirm: [result: string];+}>();++const STORAGE_KEY = "dbx:delimited-list-settings";++interface DelimitedListSettings {+ columnDelimiter: string;+ resultDelimiter: string;+ quoteChar: string;+ wrapColumn: number;+ prefixText: string;+ suffixText: string;+}++const DEFAULT_SETTINGS: DelimitedListSettings = {+ columnDelimiter: "\\n",+ resultDelimiter: ",",+ quoteChar: "'",+ wrapColumn: 80,+ prefixText: "",+ suffixText: "",+};++function loadSettings(): DelimitedListSettings {+ try {+ const raw = localStorage.getItem(STORAGE_KEY);+ if (raw) return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) };+ } catch {+ /* ignore */+ }+ return { ...DEFAULT_SETTINGS };+}++const saved = loadSettings();+const columnDelimiter = ref(saved.columnDelimiter);+const resultDelimiter = ref(saved.resultDelimiter);+const quoteChar = ref(saved.quoteChar);+const wrapColumn = ref(saved.wrapColumn);+const prefixText = ref(saved.prefixText);+const suffixText = ref(saved.suffixText);++function saveSettings() {+ try {+ const settings: DelimitedListSettings = {+ columnDelimiter: columnDelimiter.value,+ resultDelimiter: resultDelimiter.value,+ quoteChar: quoteChar.value,+ wrapColumn: wrapColumn.value,+ prefixText: prefixText.value,+ suffixText: suffixText.value,+ };+ localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));+ } catch {+ /* ignore */+ }+}++// Persist settings whenever any value changes+watch([columnDelimiter, resultDelimiter, quoteChar, wrapColumn, prefixText, suffixText], saveSettings);++function unescapeDelimiter(raw: string): string {+ return raw.replace(/\\t/g, "\t").replace(/\\n/g, "\n").replace(/\\r/g, "\r");+}++const preview = computed(() => {+ if (!props.selectedText.trim()) return "";+ return buildDelimitedList(props.selectedText);+});++function buildDelimitedList(text: string): string {+ const colDelim = unescapeDelimiter(columnDelimiter.value);+ const resDelim = resultDelimiter.value;+ const quote = quoteChar.value;+ const maxCol = wrapColumn.value;+ const prefix = prefixText.value;+ const suffix = suffixText.value;++ // Split the input text by column delimiter+ const items = text+ .split(colDelim)+ .map((s) => s.trim())+ .filter((s) => s.length > 0);++ if (items.length === 0) return "";++ // Wrap each item with quote and prefix/suffix+ const wrapped = items.map((item) => `${quote}${prefix}${item}${suffix}${quote}`);++ // Build lines respecting wrapColumn limit+ const lines: string[] = [];+ let currentLine = "";++ for (let i = 0; i < wrapped.length; i++) {+ const piece = wrapped[i];+ const separator = i > 0 ? resDelim : "";++ if (i === 0) {+ currentLine = piece;+ } else if (currentLine.length + separator.length + piece.length > maxCol && currentLine.length > 0) {+ // Start a new line beginning with the result delimiter+ lines.push(currentLine + resDelim);+ currentLine = piece;+ } else {+ currentLine += separator + piece;+ }+ }++ if (currentLine.length > 0) {+ lines.push(currentLine);+ }++ return lines.join("\n");+}++function confirm() {+ const result = buildDelimitedList(props.selectedText);+ open.value = false;+ emit("confirm", result);+}++async function copyPreview() {+ try {+ await copyToClipboard(preview.value);+ toast(t("grid.copied"));+ } catch (e: any) {+ toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);+ }+}+</script>++<template>+ <Dialog v-model:open="open">+ <DialogContent class="max-h-[86vh] border border-border !bg-background text-foreground shadow-2xl !backdrop-blur-none sm:max-w-[620px]">+ <DialogHeader>+ <DialogTitle class="flex items-center gap-2">+ <List class="h-5 w-5 text-primary" />+ {{ t("editor.delimitedList.title") }}+ </DialogTitle>+ </DialogHeader>++ <div class="grid gap-4">+ <div class="grid grid-cols-2 gap-4">+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.columnDelimiter") }}</Label>+ <Input v-model="columnDelimiter" class="h-8 font-mono text-xs" />+ </div>+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.resultDelimiter") }}</Label>+ <Input v-model="resultDelimiter" class="h-8 font-mono text-xs" />+ </div>+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.quoteChar") }}</Label>+ <Input v-model="quoteChar" class="h-8 font-mono text-xs" />+ </div>+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.wrapColumn") }}</Label>+ <Input v-model.number="wrapColumn" type="number" class="h-8 font-mono text-xs" min="1" />+ </div>+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.prefixText") }}</Label>+ <Input v-model="prefixText" class="h-8 font-mono text-xs" />+ </div>+ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.suffixText") }}</Label>+ <Input v-model="suffixText" class="h-8 font-mono text-xs" />+ </div>+ </div>++ <div class="grid gap-1.5">+ <Label class="text-xs">{{ t("editor.delimitedList.preview") }}</Label>+ <pre class="max-h-48 min-w-0 overflow-auto rounded-md bg-muted px-3 py-2 text-xs font-mono whitespace-pre">{{ preview || t("editor.delimitedList.emptyPreview") }}</pre>+ </div>+ </div>++ <DialogFooter>+ <Button variant="outline" @click="open = false">{{ t("dangerDialog.cancel") }}</Button>+ <Button variant="outline" @click="copyPreview" :disabled="!preview">+ <Copy class="mr-1.5 h-4 w-4" />+ {{ t("grid.copy") }}+ </Button>+ <Button @click="confirm" :disabled="!preview">{{ t("editor.delimitedList.confirm") }}</Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+</template>diff --git a/apps/desktop/src/components/editor/EditorSearchPanel.vue b/apps/desktop/src/components/editor/EditorSearchPanel.vueindex 23b237185d..0a037f1bab 100644--- a/apps/desktop/src/components/editor/EditorSearchPanel.vue+++ b/apps/desktop/src/components/editor/EditorSearchPanel.vue@@ -5,7 +5,7 @@ import type { EditorView } from "@codemirror/view";import { EditorSelection } from "@codemirror/state";import { setSearchQuery, openSearchPanel as cmOpenSearchPanel, findNext as cmFindNext, findPrevious as cmFindPrevious, replaceNext as cmReplaceNext, replaceAll as cmReplaceAll } from "@codemirror/search";import { ChevronUp, ChevronDown, ChevronRight, X } from "@lucide/vue";-import { createEditorSearchQuery } from "@/lib/editor/editorSearchQuery";+import { collectEditorSearchMatches, createEditorSearchQuery, replaceEditorSearchMatches } from "@/lib/editor/editorSearchQuery";const props = defineProps<{view: EditorView | null;@@ -26,6 +26,11 @@ const searchInputRef = ref<HTMLInputElement>();const replaceInputRef = ref<HTMLInputElement>();const matchCountLimited = ref(false);+// Scoped search: restrict find/replace to the original selection range+let searchScopeFrom: number | null = null;+let searchScopeTo: number | null = null;+const inSelectionScope = ref(false);+const SEARCH_UPDATE_DELAY_MS = 120;const DOCUMENT_SEARCH_UPDATE_DELAY_MS = 500;const MATCH_COUNT_LIMIT = 1000;@@ -57,13 +62,83 @@ function clearSearchQuery() {const selection = v.state.selection.main;v.dispatch({selection: EditorSelection.single(selection.head),- effects: setSearchQuery.of(createEditorSearchQuery({ search: "", caseSensitive: false, useRegex: false })),+ effects: setSearchQuery.of(+ createEditorSearchQuery({+ search: "",+ caseSensitive: false,+ useRegex: false,+ }),+ ),});matchCount.value = 0;currentMatchIndex.value = 0;matchCountLimited.value = false;}+/**+ * Get replacement text for a regex match, supporting capture groups.+ */+function computeReplacementForMatch(v: EditorView, matchFrom: number, matchTo: number): string {+ if (!useRegex.value) return replaceText.value;+ const matchedText = v.state.sliceDoc(matchFrom, matchTo);+ try {+ const re = new RegExp(searchText.value, caseSensitive.value ? "" : "i");+ const m = re.exec(matchedText);+ if (!m) return replaceText.value;+ return replaceText.value.replace(/\$(\d+|&)/g, (_, ref) => {+ if (ref === "&") return m[0];+ const idx = parseInt(ref, 10);+ return idx < m.length ? (m[idx] ?? "") : `$${ref}`;+ });+ } catch {+ return replaceText.value;+ }+}++/**+ * Collect all search matches within the scoped range.+ */+function collectScopedMatches(v: EditorView, limit = MATCH_COUNT_LIMIT) {+ if (searchScopeFrom == null || searchScopeTo == null) return null;+ const q = createEditorSearchQuery({+ search: searchText.value,+ caseSensitive: caseSensitive.value,+ useRegex: useRegex.value,+ });+ if (!q.valid) return null;+ return collectEditorSearchMatches(q, v.state, searchScopeFrom, searchScopeTo, limit);+}++/**+ * Find next/previous match within the scoped range.+ * Returns true if a match was found.+ */+function findInScope(direction: "next" | "prev"): boolean {+ const v = props.view;+ if (!v || !searchText.value || searchScopeFrom == null || searchScopeTo == null) return false;+ const matches = collectScopedMatches(v);+ if (!matches || matches.length === 0) return false;++ const cursor = v.state.selection.main.head;+ let target: { from: number; to: number } | null = null;++ if (direction === "next") {+ target = matches.find((m) => m.from >= cursor) ?? matches.find((m) => m.from >= searchScopeFrom!) ?? null;+ } else {+ const before = matches.filter((m) => m.to <= cursor);+ target = before.length > 0 ? before[before.length - 1] : matches[matches.length - 1];+ }++ if (target) {+ v.dispatch({+ selection: EditorSelection.range(target.from, target.to),+ scrollIntoView: true,+ });+ return true;+ }+ return false;+}+function updateMatchInfo(autoSelect = false) {const v = props.view;if (!v || !searchText.value) {@@ -73,6 +148,27 @@ function updateMatchInfo(autoSelect = false) {return;}try {+ // Scoped: use custom find logic+ if (searchScopeFrom != null && searchScopeTo != null) {+ if (autoSelect) findInScope("next");+ const matches = collectScopedMatches(v);+ if (!matches) {+ matchCount.value = 0;+ currentMatchIndex.value = 0;+ matchCountLimited.value = false;+ return;+ }+ const count = matches.length;+ matchCount.value = count;+ matchCountLimited.value = count >= MATCH_COUNT_LIMIT;+ const selFrom = v.state.selection.main.from;+ const selTo = v.state.selection.main.to;+ const idx = matches.findIndex((m) => m.from === selFrom && m.to === selTo);+ currentMatchIndex.value = idx >= 0 ? idx + 1 : count > 0 ? 1 : 0;+ return;+ }++ // Full document: use CodeMirror built-inconst q = createEditorSearchQuery({search: searchText.value,caseSensitive: caseSensitive.value,@@ -140,8 +236,21 @@ function openSearch(): boolean {const v = props.view;if (v) {cmOpenSearchPanel(v);- const sel = v.state.sliceDoc(v.state.selection.main.from, v.state.selection.main.to);- if (sel && !sel.includes("\n")) searchText.value = sel;+ const sel = v.state.selection.main;+ const selText = v.state.sliceDoc(sel.from, sel.to);+ if (selText && !selText.includes("\n")) {+ searchText.value = selText;+ }+ // Set scope when there's a multi-line selection+ if (!sel.empty && selText.includes("\n")) {+ searchScopeFrom = sel.from;+ searchScopeTo = sel.to;+ inSelectionScope.value = true;+ } else {+ searchScopeFrom = null;+ searchScopeTo = null;+ inSelectionScope.value = false;+ }}nextTick(() => {searchInputRef.value?.focus();@@ -166,6 +275,9 @@ function closeSearch() {searchVisible.value = false;showReplace.value = false;clearDocumentSearchUpdate();+ searchScopeFrom = null;+ searchScopeTo = null;+ inSelectionScope.value = false;const v = props.view;if (v) {clearSearchQuery();@@ -177,28 +289,85 @@ function closeSearch() {function nextMatch() {const v = props.view;if (!v || !searchText.value) return;- cmFindNext(v);+ if (searchScopeFrom != null) {+ findInScope("next");+ } else {+ cmFindNext(v);+ }updateMatchInfo();}function prevMatch() {const v = props.view;if (!v || !searchText.value) return;- cmFindPrevious(v);+ if (searchScopeFrom != null) {+ findInScope("prev");+ } else {+ cmFindPrevious(v);+ }updateMatchInfo();}function doReplace() {const v = props.view;if (!v || !searchText.value) return;- cmReplaceNext(v);- updateMatchInfo();++ if (searchScopeFrom != null && searchScopeTo != null) {+ // Scoped replace: find and replace next match within scope+ const sel = v.state.selection.main;+ const q = createEditorSearchQuery({+ search: searchText.value,+ caseSensitive: caseSensitive.value,+ useRegex: useRegex.value,+ });+ if (!q.valid) return;+ const iter = q.getCursor(v.state);+ let r = iter.next();+ let target: { from: number; to: number } | null = null;+ while (!r.done) {+ if (r.value.from >= searchScopeFrom && r.value.to <= searchScopeTo && r.value.from >= sel.from) {+ target = { from: r.value.from, to: r.value.to };+ break;+ }+ r = iter.next();+ }+ if (target) {+ const insertText = computeReplacementForMatch(v, target.from, target.to);+ const tr = v.state.changeByRange((range) => {+ if (range.from === target!.from && range.to === target!.to) {+ return {+ changes: { from: target!.from, to: target!.to, insert: insertText },+ range: EditorSelection.range(target!.from, target!.from + insertText.length),+ };+ }+ return { range };+ });+ v.dispatch(tr);+ // Map scope through changes+ searchScopeFrom = tr.changes.mapPos(searchScopeFrom);+ searchScopeTo = tr.changes.mapPos(searchScopeTo);+ } else {+ // Wrap around to start of scope+ findInScope("next");+ }+ } else {+ cmReplaceNext(v);+ }+ updateMatchInfo(true);}function doReplaceAll() {const v = props.view;if (!v || !searchText.value) return;- cmReplaceAll(v);++ if (searchScopeFrom != null && searchScopeTo != null) {+ // Scoped replace all: collect matches and replace+ const matches = collectScopedMatches(v, Number.POSITIVE_INFINITY);+ if (!matches || matches.length === 0) return;+ replaceEditorSearchMatches(v, matches, (match) => computeReplacementForMatch(v, match.from, match.to));+ } else {+ cmReplaceAll(v);+ }updateMatchInfo();}@@ -231,7 +400,12 @@ onBeforeUnmount(() => {}});-defineExpose({ openSearch, openReplace, closeSearch, scheduleDocumentSearchUpdate });+defineExpose({+ openSearch,+ openReplace,+ closeSearch,+ scheduleDocumentSearchUpdate,+});</script><template>@@ -272,6 +446,9 @@ defineExpose({ openSearch, openReplace, closeSearch, scheduleDocumentSearchUpdat<span class="min-w-[3.4rem] shrink-0 text-center text-xs" :class="searchText && matchCount === 0 ? 'text-destructive' : 'text-muted-foreground'">{{ searchText && matchCount > 0 ? `${currentMatchIndex}/${matchCount}${matchCountLimited ? "+" : ""}` : t("editor.search.noResults") }}</span>+ <span v-if="inSelectionScope" class="shrink-0 rounded bg-accent px-1 py-0.5 text-[10px] font-medium text-muted-foreground" :title="t('editor.search.inSelection')">+ {{ t("editor.search.inSelection") }}+ </span><button class="flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground" :title="t('editor.search.prevMatch')" @click="prevMatch"><ChevronUp class="h-4 w-4" /></button>diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vueindex 01b8a4303a..e595e13e1c 100644--- a/apps/desktop/src/components/editor/QueryEditor.vue+++ b/apps/desktop/src/components/editor/QueryEditor.vue@@ -1,12 +1,13 @@<script setup lang="ts">import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated, watch, shallowRef, computed, nextTick } from "vue";-import { CaseLower, CaseUpper, Code2, FileCode, Pencil, PencilRuler, Play, Copy, Sparkles, Table2, TextSelect } from "@lucide/vue";+import { CaseLower, CaseUpper, Code2, FileCode, Pencil, PencilRuler, Play, Copy, List, Search, Sparkles, Table2, TextSelect, Trash2 } from "@lucide/vue";import { useI18n } from "vue-i18n";import type { CompletionContext } from "@codemirror/autocomplete";import type { EditorView as EditorViewType } from "@codemirror/view";import { search as cmSearch } from "@codemirror/search";import EditorSearchPanel from "./EditorSearchPanel.vue";import SqlExecutionTargetPicker from "./SqlExecutionTargetPicker.vue";+import DelimitedListDialog from "./DelimitedListDialog.vue";import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";import { copyToClipboard, readTextFromClipboard } from "@/lib/common/clipboard";import { resolveExecutableSql, type SqlExecutionSnapshot, type SqlExecutionOverride, type SqlExecutionCandidate } from "@/lib/sql/sqlExecutionTarget";@@ -15,6 +16,7 @@ import { executableStatementRangeAtCursor, executableStatementRangeCacheForDoc,import { currentStatementFrameRangeTo, visualSqlColumnsWithInlineHints } from "@/lib/sql/currentStatementFrame";import { expandToSqlStatementWindow, parseInsertValueHints } from "@/lib/sql/insertValueHints";import { formatSqlText, type SqlFormatDialect } from "@/lib/sql/sqlFormatter";+import { blankLineDeletionChanges, replaceSelectedEditorText } from "@/lib/editor/queryEditorTextEdits";import { buildSqlInConditionFromPasteSource, insertTextForSqlInCondition } from "@/lib/sql/sqlInListPaste";import { resolveSqlSingleQuoteKeyAction } from "@/lib/sql/sqlQuoteCaret";import { formatMongoShellText } from "@/lib/mongo/mongoFormatter";@@ -203,6 +205,28 @@ const pickerCandidates = ref<SqlExecutionCandidate[]>([]);const pickerActiveIndex = ref(0);const pickerAnchor = ref<{ left: number; top: number }>();+// Delimited list dialog state+const delimitedListOpen = ref(false);+const delimitedListSelectedText = ref("");++function openDelimitedListDialog() {+ if (props.readOnly) return;+ if (!selectedSql.value.trim()) {+ toast(t("editor.delimitedList.selectFirst"), 3000);+ return;+ }+ delimitedListSelectedText.value = selectedSql.value;+ delimitedListOpen.value = true;+ focusEditor();+}++function applyDelimitedListResult(result: string) {+ const currentView = view.value;+ if (!currentView || props.readOnly) return;+ if (!replaceSelectedEditorText(currentView, result)) return;+ focusEditor();+}+const executeContextMenuLabel = computed(() => t(hasSelectedSql.value ? "editor.contextMenu.executeSelection" : "editor.contextMenu.executeCurrent"));interface EditorGestureEvent extends Event {@@ -256,8 +280,18 @@ let codeMirrorSelectAll: typeof import("@codemirror/commands").selectAll | nulllet codeMirrorInsertNewlineKeepIndent: typeof import("@codemirror/commands").insertNewlineKeepIndent | null = null;let codeMirrorToggleLineComment: typeof import("@codemirror/commands").toggleLineComment | null = null;let setSqlDiagnosticsEffect: import("@codemirror/state").StateEffectType<SqlSemanticDiagnostic[]> | null = null;-let setPreviewRangeEffect: import("@codemirror/state").StateEffectType<{ from: number; to: number } | null> | null = null;-let setResultSourceRangeEffect: import("@codemirror/state").StateEffectType<{ from: number; to: number } | null> | null = null;+let setPreviewRangeEffect:+ | import("@codemirror/state").StateEffectType<{+ from: number;+ to: number;+ } | null>+ | null = null;+let setResultSourceRangeEffect:+ | import("@codemirror/state").StateEffectType<{+ from: number;+ to: number;+ } | null>+ | null = null;let setStatementExecutionMarkersEffect: import("@codemirror/state").StateEffectType<StatementExecutionMarker[]> | null = null;let previewRangeComp: import("@codemirror/state").Compartment | null = null;let buildPreviewRangeExtension: (() => import("@codemirror/state").Extension) | null = null;@@ -404,7 +438,11 @@ function handleTab(view: EditorViewType): boolean {const line = state.doc.lineAt(sel.from);const before = line.text.slice(0, sel.from - line.from);if (/^\s*$/.test(before)) return codeMirrorIndentMore?.(view) ?? false;- dispatch(state.update(state.replaceSelection(editorIndentUnit()), { userEvent: "input.type" }));+ dispatch(+ state.update(state.replaceSelection(editorIndentUnit()), {+ userEvent: "input.type",+ }),+ );return true;}@@ -566,12 +604,32 @@ function syncContextMenuStateAtEvent(currentView: EditorViewType, event: MouseEvconst sql = currentView.state.doc.toString();if (!props.connectionId || props.database == null) {- const candidate = queryTableCandidateAtSqlPosition({ connectionId: "", database: props.database ?? "", schema: props.schema, databaseType: props.databaseType, sql, position: pos });- contextObjectTarget.value = candidate ? { name: candidate.tableName, database: candidate.database, schema: candidate.schema } : null;+ const candidate = queryTableCandidateAtSqlPosition({+ connectionId: "",+ database: props.database ?? "",+ schema: props.schema,+ databaseType: props.databaseType,+ sql,+ position: pos,+ });+ contextObjectTarget.value = candidate+ ? {+ name: candidate.tableName,+ database: candidate.database,+ schema: candidate.schema,+ }+ : null;return;}- const parsedCandidate = queryTableCandidateAtSqlPosition({ connectionId: props.connectionId, database: props.database, schema: props.schema, databaseType: props.databaseType, sql, position: pos });+ const parsedCandidate = queryTableCandidateAtSqlPosition({+ connectionId: props.connectionId,+ database: props.database,+ schema: props.schema,+ databaseType: props.databaseType,+ sql,+ position: pos,+ });if (!parsedCandidate) {contextObjectTarget.value = null;return;@@ -648,7 +706,11 @@ function selectedRangeAtPointer(currentView: EditorViewType, event: MouseEvent)if (range.empty) return null;const pos = currentView.posAtCoords({ x: event.clientX, y: event.clientY }, false);if (pos == null || pos < range.from || pos > range.to) return null;- return { from: range.from, to: range.to, text: currentView.state.sliceDoc(range.from, range.to) };+ return {+ from: range.from,+ to: range.to,+ text: currentView.state.sliceDoc(range.from, range.to),+ };}function moveOrCopySelectionToPointer(currentView: EditorViewType, selection: { from: number; to: number; text: string }, event: MouseEvent) {@@ -754,9 +816,15 @@ function startEditorSelectionDrag(currentView: EditorViewType, event: MouseEventmoveOrCopySelectionToPointer(currentView, selection, upEvent);return;}- const pos = currentView.posAtCoords({ x: upEvent.clientX, y: upEvent.clientY });+ const pos = currentView.posAtCoords({+ x: upEvent.clientX,+ y: upEvent.clientY,+ });if (pos != null) {- currentView.dispatch({ selection: { anchor: pos }, userEvent: "select.pointer" });+ currentView.dispatch({+ selection: { anchor: pos },+ userEvent: "select.pointer",+ });currentView.focus();}};@@ -824,7 +892,11 @@ function convertSelectedSqlCase(mode: SelectionCaseMode): boolean {});if (!transaction.changes.empty) {- currentView.dispatch({ ...transaction, scrollIntoView: true, userEvent: "input" });+ currentView.dispatch({+ ...transaction,+ scrollIntoView: true,+ userEvent: "input",+ });focusEditor();return true;}@@ -844,7 +916,12 @@ async function pasteClipboardAsSqlInCondition(): Promise<boolean> {try {source = await readTextFromClipboard();} catch (e: any) {- toast(t("editor.exPasteClipboardReadFailed", { message: e?.message || String(e) }), 5000);+ toast(+ t("editor.exPasteClipboardReadFailed", {+ message: e?.message || String(e),+ }),+ 5000,+ );focusEditor();return false;}@@ -875,6 +952,26 @@ async function pasteClipboardAsSqlInCondition(): Promise<boolean> {return true;}+function deleteEmptyLines() {+ const currentView = view.value;+ if (!currentView || props.readOnly) return;++ const state = currentView.state;+ const selection = state.selection.main;+ const changes = blankLineDeletionChanges(state.doc, selection);+ if (changes.length === 0) return;++ currentView.dispatch({+ changes,+ scrollIntoView: true,+ });+ focusEditor();+}++function openFindReplaceFromContextMenu() {+ openSearch();+}+function emitContextObjectAction(action: QueryContextObjectAction) {if (!contextObjectTarget.value) return;const route = queryContextObjectRoute(action, contextObjectTarget.value);@@ -899,15 +996,40 @@ function contextObjectMenuItem(action: QueryContextObjectAction): ContextMenuIteconst disabled = !contextObjectTarget.value;switch (action) {case "view-data":- return { label: t("contextMenu.viewData"), action: () => emitContextObjectAction(action), disabled, icon: Table2 };+ return {+ label: t("contextMenu.viewData"),+ action: () => emitContextObjectAction(action),+ disabled,+ icon: Table2,+ };case "edit-table-structure":- return { label: t("contextMenu.editStructure"), action: () => emitContextObjectAction(action), disabled, icon: PencilRuler };+ return {+ label: t("contextMenu.editStructure"),+ action: () => emitContextObjectAction(action),+ disabled,+ icon: PencilRuler,+ };case "edit-view":- return { label: t("contextMenu.editView"), action: () => emitContextObjectAction(action), disabled, icon: Pencil };+ return {+ label: t("contextMenu.editView"),+ action: () => emitContextObjectAction(action),+ disabled,+ icon: Pencil,+ };case "view-source":- return { label: t("contextMenu.viewSource"), action: () => emitContextObjectAction(action), disabled, icon: Code2 };+ return {+ label: t("contextMenu.viewSource"),+ action: () => emitContextObjectAction(action),+ disabled,+ icon: Code2,+ };case "view-ddl":- return { label: t("contextMenu.viewDdl"), action: () => emitContextObjectAction(action), disabled, icon: FileCode };+ return {+ label: t("contextMenu.viewDdl"),+ action: () => emitContextObjectAction(action),+ disabled,+ icon: FileCode,+ };}}@@ -993,7 +1115,32 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => {icon: CaseLower,shortcut: shortcuts.lowercaseSelection,},- { label: t("editor.contextMenu.selectAll"), action: selectAllSqlFromContextMenu, icon: TextSelect, shortcut: shortcuts.selectAll },+ {+ label: t("editor.contextMenu.delimitedList"),+ action: openDelimitedListDialog,+ disabled: props.readOnly || !canCopySelectedSql.value,+ icon: List,+ },+ { label: "", separator: true },+ {+ label: t("editor.contextMenu.findReplace"),+ action: openFindReplaceFromContextMenu,+ icon: Search,+ shortcut: shortcuts.find,+ },+ {+ label: t("editor.contextMenu.deleteEmptyLines"),+ action: deleteEmptyLines,+ disabled: props.readOnly,+ icon: Trash2,+ },+ { label: "", separator: true },+ {+ label: t("editor.contextMenu.selectAll"),+ action: selectAllSqlFromContextMenu,+ icon: TextSelect,+ shortcut: shortcuts.selectAll,+ },];});@@ -1384,7 +1531,12 @@ async function resolveSqlHoverTooltip(currentView: EditorViewType, pos: number)const parts = splitQualifiedIdentifier(identifier);const name = parts[parts.length - 1] ?? identifier;const qualifier = parts.length > 1 ? parts[parts.length - 2] : undefined;- const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED ? buildSqlSemanticModel(sql, pos, { databaseType: props.databaseType, dialect: props.syntaxDialect ?? props.dialect }) : null;+ const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED+ ? buildSqlSemanticModel(sql, pos, {+ databaseType: props.databaseType,+ dialect: props.syntaxDialect ?? props.dialect,+ })+ : null;const semanticTarget = semanticModel ? resolveSqlSemanticNavigationTarget(semanticModel, parts) : null;const semanticQualifierIsRowSource = !!qualifier && !!semanticTarget && (semanticTarget.alias?.toLowerCase() === qualifier.toLowerCase() || semanticTarget.source.name.toLowerCase() === qualifier.toLowerCase());const tableLookupName = semanticTarget && !semanticQualifierIsRowSource ? semanticTarget.name : name;@@ -1463,7 +1615,10 @@ function sqlErrorDecorationRange(currentState: import("@codemirror/state").Editofunction sqlTextSpanToRange(sql: string, span: SqlTextSpan): { from: number; to: number } | null {if (!span.start_line || !span.start_column) return null;- const from = lineColumnToOffset(sql, { line: span.start_line - 1, column: span.start_column - 1 });+ const from = lineColumnToOffset(sql, {+ line: span.start_line - 1,+ column: span.start_column - 1,+ });const to = lineColumnToOffset(sql, {line: Math.max(span.end_line - 1, span.start_line - 1),column: Math.max(span.end_column, span.start_column),@@ -1477,9 +1632,24 @@ function sqlSemanticDecorationRanges(currentState: import("@codemirror/state").Ereturn semanticDiagnostics.map((diagnostic) => {const range = sqlTextSpanToRange(sql, diagnostic.span);- return range ? { ...range, message: diagnostic.message, severity: diagnostic.severity } : null;+ return range+ ? {+ ...range,+ message: diagnostic.message,+ severity: diagnostic.severity,+ }+ : null;})- .filter((range): range is { from: number; to: number; message: string; severity: "error" | "warning" } => !!range);+ .filter(+ (+ range,+ ): range is {+ from: number;+ to: number;+ message: string;+ severity: "error" | "warning";+ } => !!range,+ );}function reconfigureDiagnostics() {@@ -1593,7 +1763,9 @@ async function ensureColumnsForSemanticDiagnostics(tables: SqlTableReference[]):const targets: SqlTableReference[] = [];for (const table of tables) {if (isStatementLocalSemanticTable(table)) continue;- const tableWithInlineColumns = table as SqlTableReference & { columns?: string[] };+ const tableWithInlineColumns = table as SqlTableReference & {+ columns?: string[];+ };if (tableWithInlineColumns.columns && tableWithInlineColumns.columns.length > 0) continue;const cacheKey = completionCacheKey(table);if (cachedColumnsByTable.has(cacheKey)) continue;@@ -1642,7 +1814,9 @@ async function refreshSemanticDiagnostics(options: { preserveOutsideRanges?: booif (props.databaseType === "redis") {// Redis has no SQL semantics; run command-name / arity / quote / danger checks instead.if (!shouldRunRedisDiagnostics(sql, currentView.state.selection.main.head)) {- scheduleSemanticDiagnostics(900, { preserveOutsideRanges: options.preserveOutsideRanges });+ scheduleSemanticDiagnostics(900, {+ preserveOutsideRanges: options.preserveOutsideRanges,+ });return;}setSemanticDiagnostics(buildRedisSyntaxDiagnostics(sql));@@ -1653,11 +1827,15 @@ async function refreshSemanticDiagnostics(options: { preserveOutsideRanges?: booreturn;}if (!shouldRunSqlSemanticDiagnostics(sql, currentView.state.selection.main.head, { databaseType: props.databaseType })) {- scheduleSemanticDiagnostics(1200, { preserveOutsideRanges: options.preserveOutsideRanges });+ scheduleSemanticDiagnostics(1200, {+ preserveOutsideRanges: options.preserveOutsideRanges,+ });return;}if (codeMirrorCompletionStatus?.(currentView.state) && isSqlSemanticDiagnosticInputContext(sql, currentView.state.selection.main.head, { databaseType: props.databaseType })) {- scheduleSemanticDiagnostics(900, { preserveOutsideRanges: options.preserveOutsideRanges });+ scheduleSemanticDiagnostics(900, {+ preserveOutsideRanges: options.preserveOutsideRanges,+ });return;}@@ -1675,14 +1853,22 @@ async function refreshSemanticDiagnostics(options: { preserveOutsideRanges?: booif (runId !== semanticDiagnosticRunId) return;const semanticCursor = Math.max(0, Math.min(currentView.state.selection.main.head - range.from, range.sql.length));- const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED ? buildSqlSemanticModel(range.sql, semanticCursor, { databaseType: props.databaseType, dialect: props.syntaxDialect ?? props.dialect }) : null;+ const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED+ ? buildSqlSemanticModel(range.sql, semanticCursor, {+ databaseType: props.databaseType,+ dialect: props.syntaxDialect ?? props.dialect,+ })+ : null;const semanticAnalysis = semanticModel ? mergeSqlSemanticReferenceAnalysis(analysis, semanticModel) : analysis;const { tables, missingTables } = await enrichSemanticDiagnosticTables(semanticAnalysis.tables);const columnMetadataMissingTables = await ensureColumnsForSemanticDiagnostics(tables);for (const tableKey of columnMetadataMissingTables) missingTables.add(tableKey);if (runId !== semanticDiagnosticRunId) return;- const enrichedAnalysis: SqlReferenceAnalysis = { ...semanticAnalysis, tables };+ const enrichedAnalysis: SqlReferenceAnalysis = {+ ...semanticAnalysis,+ tables,+ };nextDiagnostics.push(...offsetSqlSemanticDiagnostics(buildSqlSemanticDiagnostics(enrichedAnalysis, {@@ -1786,7 +1972,10 @@ function insertDroppedTableReference(currentView: EditorViewType, event: DragEveevent.preventDefault();event.stopPropagation();- return insertTableReferencePayload(currentView, payload, { clientX: event.clientX, clientY: event.clientY });+ return insertTableReferencePayload(currentView, payload, {+ clientX: event.clientX,+ clientY: event.clientY,+ });}function onTableReferenceDropEvent(event: Event) {@@ -1960,7 +2149,9 @@ async function provideRedisCompletions(currentState: import("@codemirror/state")}if (epoch !== completionEpoch) return null;- const items = buildRedisCompletionItemsFromContext(completionContext, { keys });+ const items = buildRedisCompletionItemsFromContext(completionContext, {+ keys,+ });if (items.length === 0) return null;// Use the built-in filter (the default) so typing narrows the list and moves// the selection synchronously. `filter: false` + `validFor` are mutually@@ -2001,7 +2192,10 @@ async function provideMongoCompletions(currentState: import("@codemirror/state")if (epoch !== completionEpoch) return null;- const items = buildMongoCompletionItemsFromContext(completionContext, { collections, fields });+ const items = buildMongoCompletionItemsFromContext(completionContext, {+ collections,+ fields,+ });if (items.length === 0) return null;return {from: completionContext.from,@@ -2038,7 +2232,12 @@ async function provideSqlCompletions(context: CompletionContext) {if (!explicit && !shouldAutoOpenSqlCompletion(fullDoc, position)) return null;const legacyCompletionContext = getSqlCompletionContext(fullDoc, position);- const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED ? buildSqlSemanticModel(fullDoc, position, { databaseType: props.databaseType, dialect: props.syntaxDialect ?? props.dialect }) : null;+ const semanticModel = SEMANTIC_SQL_COMPLETION_ENABLED+ ? buildSqlSemanticModel(fullDoc, position, {+ databaseType: props.databaseType,+ dialect: props.syntaxDialect ?? props.dialect,+ })+ : null;const completionContext = semanticModel ? sqlCompletionContextFromSemantic(semanticModel, legacyCompletionContext) : legacyCompletionContext;if (!hasDatabase) {@@ -2223,7 +2422,11 @@ function buildLocalSqlCompletionResult(completionContext: ReturnType<typeof getSif (cteDef) {columnsByTable.set(refTable.name,- cteDef.columns.map((name) => ({ name, table: refTable.name, dataType: undefined })),+ cteDef.columns.map((name) => ({+ name,+ table: refTable.name,+ dataType: undefined,+ })),);continue;}@@ -2361,7 +2564,11 @@ function mergeCompletionTables(existing: SqlCompletionTable[], incoming: SqlComp} else {const existing = merged[index];// Preserve the more specific tree type if an older metadata endpoint reports a materialized view as VIEW.- merged[index] = { ...existing, ...table, type: mergeSqlObjectNavigationType(existing.type, table.type) };+ merged[index] = {+ ...existing,+ ...table,+ type: mergeSqlObjectNavigationType(existing.type, table.type),+ };}}return merged;@@ -2693,7 +2900,11 @@ onMounted(async () => {{ bracketMatching, foldGutter, indentOnInput, indentUnit, syntaxHighlighting, defaultHighlightStyle, foldKeymap, ensureSyntaxTree },{ searchKeymap },] = await Promise.all([import("@codemirror/view"), import("@codemirror/state"), import("@codemirror/lang-sql"), import("@codemirror/autocomplete"), import("@codemirror/commands"), import("@codemirror/language"), import("@codemirror/search")]);- editorViewModule = { EditorView, keymap, rectangularSelection } as typeof import("@codemirror/view");+ editorViewModule = {+ EditorView,+ keymap,+ rectangularSelection,+ } as typeof import("@codemirror/view");codeMirrorPrec = Prec;codeMirrorEditorSelection = EditorSelection;codeMirrorSnippetCompletion = snippetCompletion;@@ -2779,7 +2990,10 @@ onMounted(async () => {return [field, diagnosticTheme];};- setPreviewRangeEffect = StateEffect.define<{ from: number; to: number } | null>();+ setPreviewRangeEffect = StateEffect.define<{+ from: number;+ to: number;+ } | null>();buildPreviewRangeExtension = () => {const effectType = setPreviewRangeEffect!;const field = StateField.define({@@ -2807,7 +3021,10 @@ onMounted(async () => {}const resultSourceLineNumberMarker = new ResultSourceLineNumberMarker();- setResultSourceRangeEffect = StateEffect.define<{ from: number; to: number } | null>();+ setResultSourceRangeEffect = StateEffect.define<{+ from: number;+ to: number;+ } | null>();buildResultSourceRangeExtension = () => {const effectType = setResultSourceRangeEffect!;const markersForRange = (state: import("@codemirror/state").EditorState, range: { from: number; to: number }) => {@@ -2934,7 +3151,10 @@ onMounted(async () => {override: [async (context: CompletionContext) => provideSqlCompletions(context)],});- buildSqlLanguageExtension = () => langSql.sql({ dialect: createDbxCodeMirrorSqlDialect(langSql, props.syntaxDialect ?? props.dialect, props.databaseType) });+ buildSqlLanguageExtension = () =>+ langSql.sql({+ dialect: createDbxCodeMirrorSqlDialect(langSql, props.syntaxDialect ?? props.dialect, props.databaseType),+ });buildSqlSemanticHighlightExtension = () => [ViewPlugin.fromClass(class {@@ -2956,7 +3176,12 @@ onMounted(async () => {}const tree = ensureSyntaxTree(currentView.state, windows[windows.length - 1]?.to ?? 0, 25);if (!tree) return Decoration.set([]);- const ranges = windows.flatMap((window) => sqlSemanticTableNameSpansForSyntaxTree(sql, window, tree, { databaseType: props.databaseType, dialect: props.syntaxDialect ?? props.dialect }));+ const ranges = windows.flatMap((window) =>+ sqlSemanticTableNameSpansForSyntaxTree(sql, window, tree, {+ databaseType: props.databaseType,+ dialect: props.syntaxDialect ?? props.dialect,+ }),+ );return Decoration.set(ranges.map((range) =>Decoration.mark({@@ -3044,7 +3269,14 @@ onMounted(async () => {const classes = ["cm-db-current-statement-line"];if (lineNumber === startLine.number) classes.push("cm-db-current-statement-line--first");if (lineNumber === endLine.number) classes.push("cm-db-current-statement-line--last");- deco.push(Decoration.line({ class: classes.join(" "), attributes: { style: `--dbx-current-statement-frame-width: ${frameWidth};` } }).range(line.from));+ deco.push(+ Decoration.line({+ class: classes.join(" "),+ attributes: {+ style: `--dbx-current-statement-frame-width: ${frameWidth};`,+ },+ }).range(line.from),+ );}return Decoration.set(deco);}@@ -3137,6 +3369,26 @@ onMounted(async () => {codeMirrorTheme.of(theme),closeBracketsComp.of(closeBracketsExtension(initialSettings.autoCloseBrackets)),bracketMatching(),+ // Fix: intercept quote characters to prevent closeBrackets from+ // producing triple quotes ('''). When the cursor is immediately+ // before an auto-inserted closing quote, just skip past it.+ Prec.highest(+ EditorView.inputHandler.of((view: EditorViewType, _from: number, _to: number, text: string) => {+ if (text !== "'" && text !== '"' && text !== "`") return false;+ const pos = view.state.selection.main.head;+ const nextChar = view.state.doc.sliceString(pos, pos + 1);+ if (nextChar !== text) return false;+ // Only skip when the character ahead matches and it was auto-inserted+ // (i.e. the doc has a matching pair at this position).+ const prevChar = pos > 0 ? view.state.doc.sliceString(pos - 1, pos) : "";+ if (prevChar === text) return false; // already inside a quoted region+ view.dispatch({+ selection: { anchor: pos + 1 },+ scrollIntoView: true,+ });+ return true;+ }),+ ),hoverTooltip((currentView, pos) => resolveSqlHoverTooltip(currentView, pos)),buildSqlSignatureExtension(),diagnosticComp.of(buildSqlDiagnosticExtension()),@@ -3166,7 +3418,9 @@ onMounted(async () => {indentComp.of(indentExtension()),// Alt+drag belongs exclusively to rectangular selection. Registering the// same gesture as an added cursor preserves the previous cursor.- rectangularSelection({ eventFilter: startsQueryEditorRectangularSelection }),+ rectangularSelection({+ eventFilter: startsQueryEditorRectangularSelection,+ }),EditorView.updateListener.of((update) => {if (update.docChanged) {searchPanelRef.value?.scheduleDocumentSearchUpdate();@@ -3344,7 +3598,11 @@ onMounted(async () => {return;}- const matchedCols: Array<{ name: string; table: string; schema?: string }> = [];+ const matchedCols: Array<{+ name: string;+ table: string;+ schema?: string;+ }> = [];for (const refTable of tablesToCheck) {const cacheKey = refTable.schema ? `${refTable.schema}.${refTable.name}` : refTable.name;@@ -3385,7 +3643,9 @@ onMounted(async () => {view.value = new EditorView({ state, parent: editorRef.value });registerEditorScrollbarPointerGuard(view.value);- view.value.scrollDOM.addEventListener("scroll", scheduleEditorViewportEmit, { passive: true });+ view.value.scrollDOM.addEventListener("scroll", scheduleEditorViewportEmit, {+ passive: true,+ });restoreEditorViewport();syncContextMenuState(view.value);syncEditorFontCssVars(liveFontSize.value, initialSettings.fontFamily);@@ -3447,7 +3707,9 @@ watch(() => props.statementExecutionMarkers ?? [],(markers) => {if (!view.value || !setStatementExecutionMarkersEffect) return;- view.value.dispatch({ effects: setStatementExecutionMarkersEffect.of(markers) });+ view.value.dispatch({+ effects: setStatementExecutionMarkersEffect.of(markers),+ });},{ deep: true },);@@ -3482,7 +3744,9 @@ watch(watch([() => props.databaseType, () => props.dialect, () => props.syntaxDialect], () => {executableStatementRangeCache = null;if (!view.value || !sqlLanguageComp || !buildSqlLanguageExtension || !sqlSemanticHighlightComp || !buildSqlSemanticHighlightExtension) return;- view.value.dispatch({ effects: [sqlLanguageComp.reconfigure(buildSqlLanguageExtension()), sqlSemanticHighlightComp.reconfigure(buildSqlSemanticHighlightExtension())] });+ view.value.dispatch({+ effects: [sqlLanguageComp.reconfigure(buildSqlLanguageExtension()), sqlSemanticHighlightComp.reconfigure(buildSqlSemanticHighlightExtension())],+ });});watch(@@ -3743,7 +4007,15 @@ function scrollCursorIntoView() {});}-defineExpose({ openSearch, openReplace, scrollCursorIntoView, requestExecute, pasteClipboardAsSqlInCondition, previewStatementRange, refreshCompletionCache });+defineExpose({+ openSearch,+ openReplace,+ scrollCursorIntoView,+ requestExecute,+ pasteClipboardAsSqlInCondition,+ previewStatementRange,+ refreshCompletionCache,+});</script><template>@@ -3763,6 +4035,7 @@ defineExpose({ openSearch, openReplace, scrollCursorIntoView, requestExecute, pa</CustomContextMenu><EditorSearchPanel ref="searchPanelRef" :view="view" /><SqlExecutionTargetPicker v-if="pickerVisible" :candidates="pickerCandidates" :active-index="pickerActiveIndex" :anchor="pickerAnchor" @update:active-index="onPickerActiveIndexChange" @confirm="onPickerConfirm" @cancel="closePicker" />+ <DelimitedListDialog v-model:open="delimitedListOpen" :selected-text="delimitedListSelectedText" @confirm="applyDelimitedListResult" /></div></template>diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex a19edcf9e8..42ddd2f8fc 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -629,8 +629,24 @@ export default {sendToAi: "Send to AI",uppercaseSelection: "Convert to uppercase",lowercaseSelection: "Convert to lowercase",+ delimitedList: "Convert to delimited list",+ findReplace: "Find/Replace",+ deleteEmptyLines: "Delete empty lines",selectAll: "Select all",},+ delimitedList: {+ title: "Convert to Delimited List",+ columnDelimiter: "Column delimiter",+ resultDelimiter: "Result delimiter",+ quoteChar: "Quote character",+ wrapColumn: "Wrap at column",+ prefixText: "Prefix text",+ suffixText: "Suffix text",+ preview: "Preview",+ emptyPreview: "Nothing to preview",+ confirm: "Confirm",+ selectFirst: "Please select list text",+ },search: {find: "Find",replace: "Replace",@@ -643,6 +659,7 @@ export default {nextMatch: "Next (Enter)",close: "Close (Esc)",noResults: "No results",+ inSelection: "In selection",},executionPicker: {title: "Execution Target",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex c34f70b2c3..080f254c4e 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -611,6 +611,9 @@ export default withEnglishFallback({uppercaseSelection: "Convertir a mayusculas",lowercaseSelection: "Convertir a minusculas",selectAll: "Seleccionar todo",+ delimitedList: "Convertir a lista delimitada",+ findReplace: "Buscar/Reemplazar",+ deleteEmptyLines: "Eliminar líneas vacías",},search: {find: "Buscar",@@ -624,6 +627,7 @@ export default withEnglishFallback({nextMatch: "Siguiente (Enter)",close: "Cerrar (Esc)",noResults: "Sin resultados",+ inSelection: "En la selección",},executionPicker: {title: "Execution Target",@@ -634,6 +638,19 @@ export default withEnglishFallback({},statementExecutionSucceeded: "{count} sentencias exitosas",statementExecutionFailed: "{count} sentencias fallidas",+ delimitedList: {+ title: "Convertir a lista delimitada",+ columnDelimiter: "Delimitador de columna",+ resultDelimiter: "Delimitador de resultado",+ quoteChar: "Carácter de comillas para cadenas",+ wrapColumn: "Ajustar en columna",+ prefixText: "Texto de prefijo",+ suffixText: "Texto de sufijo",+ preview: "Vista previa",+ emptyPreview: "Sin contenido para previsualizar",+ confirm: "Confirmar",+ selectFirst: "Seleccione el texto de la lista",+ },},tabs: {sql: "SQL",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex de1b69f2ac..5724285fe0 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -609,6 +609,9 @@ export default withEnglishFallback({uppercaseSelection: "Converti in maiuscolo",lowercaseSelection: "Converti in minuscolo",selectAll: "Seleziona tutto",+ delimitedList: "Converti in lista delimitata",+ findReplace: "Trova/Sostituisci",+ deleteEmptyLines: "Elimina righe vuote",},search: {find: "Trova",@@ -622,6 +625,7 @@ export default withEnglishFallback({nextMatch: "Successivo (Enter)",close: "Chiudi (Esc)",noResults: "Nessun risultato",+ inSelection: "Nella selezione",},executionPicker: {title: "Execution Target",@@ -632,6 +636,19 @@ export default withEnglishFallback({},statementExecutionSucceeded: "{count} istruzioni eseguite con successo",statementExecutionFailed: "{count} istruzioni fallite",+ delimitedList: {+ title: "Converti in lista delimitata",+ columnDelimiter: "Delimitatore di colonna",+ resultDelimiter: "Delimitatore di risultato",+ quoteChar: "Carattere di citazione stringa",+ wrapColumn: "A capo automatico alla colonna",+ prefixText: "Testo prefisso",+ suffixText: "Testo suffisso",+ preview: "Anteprima",+ emptyPreview: "Nessun contenuto da visualizzare",+ confirm: "Conferma",+ selectFirst: "Seleziona il testo della lista",+ },},tabs: {sql: "SQL",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 342ba394b6..1eefcb7254 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -608,6 +608,9 @@ export default withEnglishFallback({uppercaseSelection: "大文字に変換",lowercaseSelection: "小文字に変換",selectAll: "すべて選択",+ delimitedList: "区切り文字付きリストに変換",+ findReplace: "検索/置換",+ deleteEmptyLines: "空行を削除",},search: {find: "検索",@@ -621,6 +624,7 @@ export default withEnglishFallback({nextMatch: "次へ (Enter)",close: "閉じる (Esc)",noResults: "結果なし",+ inSelection: "選択範囲内",},executionPicker: {title: "Execution Target",@@ -632,6 +636,19 @@ export default withEnglishFallback({selectDatabaseRequired: "先にデータベースを選択してください",statementExecutionSucceeded: "{count} 件のステートメントが成功しました",statementExecutionFailed: "{count} 件のステートメントが失敗しました",+ delimitedList: {+ title: "区切り文字付きリストに変換",+ columnDelimiter: "列区切り文字",+ resultDelimiter: "結果区切り文字",+ quoteChar: "文字列引用符",+ wrapColumn: "列で折り返し",+ prefixText: "先頭テキスト",+ suffixText: "末尾テキスト",+ preview: "プレビュー",+ emptyPreview: "プレビューする内容がありません",+ confirm: "確定",+ selectFirst: "リストテキストを選択してください",+ },},tabs: {sql: "SQL",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex 6c6f05c208..ffe69479f0 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -610,6 +610,9 @@ export default withEnglishFallback({uppercaseSelection: "Converter para maiúsculas",lowercaseSelection: "Converter para minúsculas",selectAll: "Selecionar tudo",+ delimitedList: "Converter para lista delimitada",+ findReplace: "Localizar/substituir",+ deleteEmptyLines: "Excluir linhas vazias",},search: {find: "Localizar",@@ -623,6 +626,7 @@ export default withEnglishFallback({nextMatch: "Próximo (Enter)",close: "Fechar (Esc)",noResults: "Nenhum resultado",+ inSelection: "Na seleção",},executionPicker: {title: "Execution Target",@@ -633,6 +637,19 @@ export default withEnglishFallback({},statementExecutionSucceeded: "{count} instrução(ões) executada(s) com sucesso",statementExecutionFailed: "{count} instrução(ões) com falha",+ delimitedList: {+ title: "Converter para lista delimitada",+ columnDelimiter: "Delimitador de coluna",+ resultDelimiter: "Delimitador de resultado",+ quoteChar: "Caractere de aspas para strings",+ wrapColumn: "Quebrar na coluna",+ prefixText: "Texto de prefixo",+ suffixText: "Texto de sufixo",+ preview: "Visualização",+ emptyPreview: "Nada para visualizar",+ confirm: "Confirmar",+ selectFirst: "Selecione o texto da lista primeiro",+ },},tabs: {sql: "SQL",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 3c80e9811e..d50b474a91 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -631,8 +631,24 @@ export default withEnglishFallback({sendToAi: "发送到 AI",uppercaseSelection: "转为大写",lowercaseSelection: "转为小写",+ delimitedList: "转换为带分隔符的列表",+ findReplace: "查找/替换",+ deleteEmptyLines: "删除空行",selectAll: "全选",},+ delimitedList: {+ title: "转换为带分隔符的列表",+ columnDelimiter: "列分隔符",+ resultDelimiter: "结果分隔符",+ quoteChar: "字符串引号字符",+ wrapColumn: "在列处换行",+ prefixText: "前导文本",+ suffixText: "尾部文本",+ preview: "预览",+ emptyPreview: "无可预览内容",+ confirm: "确定",+ selectFirst: "请选择列表文本",+ },search: {find: "查找",replace: "替换",@@ -645,6 +661,7 @@ export default withEnglishFallback({nextMatch: "下一个 (Enter)",close: "关闭 (Esc)",noResults: "无结果",+ inSelection: "选区内",},executionPicker: {title: "执行目标",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex d6dcd50879..598dd59acb 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -610,6 +610,9 @@ export default withEnglishFallback({uppercaseSelection: "轉為大寫",lowercaseSelection: "轉為小寫",selectAll: "全選",+ delimitedList: "轉換為帶分隔符的清單",+ findReplace: "查找/取代",+ deleteEmptyLines: "刪除空行",},search: {find: "尋找",@@ -623,6 +626,7 @@ export default withEnglishFallback({nextMatch: "下一個 (Enter)",close: "關閉 (Esc)",noResults: "無結果",+ inSelection: "選取區內",},executionPicker: {title: "執行目標",@@ -633,6 +637,19 @@ export default withEnglishFallback({},statementExecutionSucceeded: "{count} 條陳述式成功",statementExecutionFailed: "{count} 條陳述式失敗",+ delimitedList: {+ title: "轉換為帶分隔符的清單",+ columnDelimiter: "欄分隔符",+ resultDelimiter: "結果分隔符",+ quoteChar: "字串引號字元",+ wrapColumn: "在欄位處換行",+ prefixText: "前置文字",+ suffixText: "尾部文字",+ preview: "預覽",+ emptyPreview: "無可預覽內容",+ confirm: "確定",+ selectFirst: "請選擇清單文字",+ },},tabs: {sql: "SQL",diff --git a/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts b/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.tsindex fc33d284fe..6a833d9d8c 100644--- a/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts+++ b/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts@@ -1,6 +1,6 @@import { EditorState } from "@codemirror/state";-import { describe, expect, it } from "vitest";-import { createEditorSearchQuery } from "@/lib/editor/editorSearchQuery";+import { describe, expect, it, vi } from "vitest";+import { collectEditorSearchMatches, createEditorSearchQuery, replaceEditorSearchMatches } from "@/lib/editor/editorSearchQuery";function matchedText(search: string, useRegex: boolean): string[] {const state = EditorState.create({@@ -25,4 +25,17 @@ describe("editorSearchQuery", () => {it("allows regular expression mode to match actual line breaks", () => {expect(matchedText(String.raw`\n`, true)).toEqual(["\n"]);});++ it("collects every scoped match when replacement is uncapped", () => {+ const state = EditorState.create({ doc: Array.from({ length: 1001 }, () => "x").join(" ") });+ const query = createEditorSearchQuery({ search: "x", caseSensitive: true, useRegex: false });+ const matches = collectEditorSearchMatches(query, state, 0, state.doc.length);+ const dispatch = vi.fn();++ expect(matches).toHaveLength(1001);+ expect(collectEditorSearchMatches(query, state, 0, state.doc.length, 1000)).toHaveLength(1000);+ expect(replaceEditorSearchMatches({ dispatch }, matches, () => "y")).toBe(true);+ expect(dispatch).toHaveBeenCalledOnce();+ expect(dispatch.mock.calls[0]?.[0].changes).toHaveLength(1001);+ });});diff --git a/apps/desktop/src/lib/__tests__/editor/queryEditorTextEdits.spec.ts b/apps/desktop/src/lib/__tests__/editor/queryEditorTextEdits.spec.tsnew file mode 100644index 0000000000..290e7c79a4--- /dev/null+++ b/apps/desktop/src/lib/__tests__/editor/queryEditorTextEdits.spec.ts@@ -0,0 +1,49 @@+import { readFileSync } from "node:fs";+import { EditorSelection, EditorState } from "@codemirror/state";+import { describe, expect, it, vi } from "vitest";+import { blankLineDeletionChanges, replaceSelectedEditorText } from "@/lib/editor/queryEditorTextEdits";++const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");++function applyBlankLineDeletion(doc: string, from: number, to: number): string {+ const state = EditorState.create({+ doc,+ selection: EditorSelection.range(from, to),+ });+ return state.update({ changes: blankLineDeletionChanges(state.doc, state.selection.main) }).state.doc.toString();+}++describe("replaceSelectedEditorText", () => {+ it("refuses to dispatch changes for a read-only editor", () => {+ const state = EditorState.create({+ doc: "a,b",+ selection: EditorSelection.range(0, 3),+ extensions: EditorState.readOnly.of(true),+ });+ const dispatch = vi.fn();++ expect(replaceSelectedEditorText({ state, dispatch }, "'a','b'")).toBe(false);+ expect(dispatch).not.toHaveBeenCalled();+ });++ it("disables and guards delimited-list generation in QueryEditor", () => {+ expect(queryEditorSource).toContain("disabled: props.readOnly || !canCopySelectedSql.value");+ expect(queryEditorSource).toMatch(/function openDelimitedListDialog\(\) \{\s+if \(props\.readOnly\) return;/);+ expect(queryEditorSource).toMatch(/function applyDelimitedListResult\(result: string\) \{[\s\S]*if \(!currentView \|\| props\.readOnly\) return;[\s\S]*replaceSelectedEditorText/);+ });+});++describe("blankLineDeletionChanges", () => {+ it("preserves one newline between adjacent non-empty SQL", () => {+ expect(applyBlankLineDeletion("a\n\nb", 2, 3)).toBe("a\nb");+ });++ it.each([+ ["partial-line selection", "select a\n\nselect b", 3, 12, "select a\nselect b"],+ ["full-line selection", "a\n \nb", 2, 5, "a\nb"],+ ["document start", "\n\na", 0, 2, "a"],+ ["document end", "a\n\n", 2, 3, "a\n"],+ ])("handles %s with line-boundary edits", (_name, doc, from, to, expected) => {+ expect(applyBlankLineDeletion(doc, from, to)).toBe(expected);+ });+});diff --git a/apps/desktop/src/lib/editor/editorSearchQuery.ts b/apps/desktop/src/lib/editor/editorSearchQuery.tsindex 2a8ca66a63..a4983c71c0 100644--- a/apps/desktop/src/lib/editor/editorSearchQuery.ts+++ b/apps/desktop/src/lib/editor/editorSearchQuery.ts@@ -1,3 +1,4 @@+import type { EditorState, TransactionSpec } from "@codemirror/state";import { SearchQuery } from "@codemirror/search";export interface EditorSearchQueryOptions {@@ -16,3 +17,35 @@ export function createEditorSearchQuery(options: EditorSearchQueryOptions): Searliteral: !options.useRegex,});}++export interface EditorSearchMatch {+ from: number;+ to: number;+}++export function collectEditorSearchMatches(query: SearchQuery, state: EditorState, from: number, to: number, limit = Number.POSITIVE_INFINITY): EditorSearchMatch[] {+ const matches: EditorSearchMatch[] = [];+ const cursor = query.getCursor(state);++ for (let result = cursor.next(); !result.done; result = cursor.next()) {+ if (result.value.from >= from && result.value.to <= to) {+ matches.push({ from: result.value.from, to: result.value.to });+ if (matches.length >= limit) break;+ }+ }++ return matches;+}++export function replaceEditorSearchMatches(view: { dispatch(spec: TransactionSpec): void }, matches: readonly EditorSearchMatch[], replacement: (match: EditorSearchMatch) => string): boolean {+ if (matches.length === 0) return false;++ view.dispatch({+ changes: matches.map((match) => ({+ from: match.from,+ to: match.to,+ insert: replacement(match),+ })),+ });+ return true;+}diff --git a/apps/desktop/src/lib/editor/queryEditorTextEdits.ts b/apps/desktop/src/lib/editor/queryEditorTextEdits.tsnew file mode 100644index 0000000000..7f30256873--- /dev/null+++ b/apps/desktop/src/lib/editor/queryEditorTextEdits.ts@@ -0,0 +1,60 @@+import type { ChangeSpec, EditorState, SelectionRange, Text, TransactionSpec } from "@codemirror/state";++export interface DispatchableEditorView {+ state: EditorState;+ dispatch(spec: TransactionSpec): void;+}++export function replaceSelectedEditorText(view: DispatchableEditorView, insert: string): boolean {+ if (view.state.readOnly) return false;++ const selection = view.state.selection.main;+ if (selection.empty) return false;++ view.dispatch({+ changes: { from: selection.from, to: selection.to, insert },+ selection: { anchor: selection.from + insert.length },+ scrollIntoView: true,+ });+ return true;+}++export function blankLineDeletionChanges(doc: Text, selection: SelectionRange): ChangeSpec[] {+ if (doc.length === 0) return [];++ const hasSelection = !selection.empty;+ const firstLine = hasSelection ? doc.lineAt(selection.from).number : 1;+ const lastSelectedPosition = hasSelection ? Math.max(selection.from, selection.to - 1) : doc.length;+ const lastLine = hasSelection ? doc.lineAt(lastSelectedPosition).number : doc.lines;+ const changes: ChangeSpec[] = [];++ let lineNumber = firstLine;+ while (lineNumber <= lastLine) {+ const line = doc.line(lineNumber);+ if (line.text.trim().length > 0) {+ lineNumber += 1;+ continue;+ }++ const firstBlankLine = line;+ let lastBlankLine = line;+ while (lineNumber < lastLine) {+ const nextLine = doc.line(lineNumber + 1);+ if (nextLine.text.trim().length > 0) break;+ lineNumber += 1;+ lastBlankLine = nextLine;+ }++ // Prefer the following separator so non-empty lines retain their existing newline.+ if (lastBlankLine.to < doc.length) {+ changes.push({ from: firstBlankLine.from, to: lastBlankLine.to + 1 });+ } else if (firstBlankLine.from > 0) {+ changes.push({ from: firstBlankLine.from - 1, to: lastBlankLine.to });+ } else {+ changes.push({ from: 0, to: doc.length });+ }+ lineNumber += 1;+ }++ return changes;+}