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): copy the current statement from the context menu
弈秋c4064a050427
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vueindex 7a74be5ea6..c726e31298 100644--- a/apps/desktop/src/components/editor/QueryEditor.vue+++ b/apps/desktop/src/components/editor/QueryEditor.vue@@ -1268,6 +1268,23 @@ function selectCurrentStatementFromContextMenu(): void {selectCurrentStatementFromView(currentView);}+/**+ * 复制光标所在的当前可执行语句(与「选中当前语句」共用同一套范围计算),+ * 方便在不选中、不执行的前提下把当前语句带走(issue #13261)。+ */+async function copyCurrentStatementFromContextMenu(): Promise<void> {+ const currentView = view.value;+ if (!currentView) return;+ const range = executableStatementRangeAtPosition(currentView, currentView.state.selection.main.head);+ if (!range || range.from === range.to) return;+ try {+ await copyToClipboard(currentView.state.sliceDoc(range.from, range.to));+ toast(t("grid.copied"));+ } catch (e: any) {+ toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);+ }+}+/*** Move the caret between executable statements without changing the document.* Reuses the same statement ranges as 「执行当前语句」/「选中当前语句」 so the@@ -1310,6 +1327,7 @@ const contextMenuActions: QueryEditorContextMenuActions = {openFindReplaceFromContextMenu,deleteEmptyLines,selectCurrentStatementFromContextMenu,+ copyCurrentStatementFromContextMenu,selectAllSqlFromContextMenu,emitContextObjectAction,openCodeSnapshot,diff --git a/apps/desktop/src/components/editor/QueryEditorContextMenu.vue b/apps/desktop/src/components/editor/QueryEditorContextMenu.vueindex 830252ae60..adc05bb05f 100644--- a/apps/desktop/src/components/editor/QueryEditorContextMenu.vue+++ b/apps/desktop/src/components/editor/QueryEditorContextMenu.vue@@ -83,6 +83,7 @@ export interface QueryEditorContextMenuActions {openFindReplaceFromContextMenu: () => void;deleteEmptyLines: () => void;selectCurrentStatementFromContextMenu: () => void;+ copyCurrentStatementFromContextMenu: () => void;selectAllSqlFromContextMenu: () => void;emitContextObjectAction: (action: QueryContextObjectAction) => void;openCodeSnapshot: () => void;@@ -406,6 +407,12 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => {icon: TextSelect,shortcut: shortcuts.selectCurrentStatement,},+ {+ sidebarActionId: "editor.contextMenu.copyCurrentStatement",+ label: t("editor.contextMenu.copyCurrentStatement"),+ action: actions.copyCurrentStatementFromContextMenu,+ icon: Copy,+ },{ label: "", separator: true },{sidebarActionId: "editor.contextMenu.findReplace",diff --git a/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts b/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.tsindex e77c6c7063..03a5a196a0 100644--- a/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts@@ -40,6 +40,7 @@ function mountMenu(layout: "full" | "grouped" = "full") {openFindReplaceFromContextMenu: vi.fn(),deleteEmptyLines: vi.fn(),selectAllSqlFromContextMenu: vi.fn(),+ copyCurrentStatementFromContextMenu: vi.fn(),emitContextObjectAction: vi.fn(),openCodeSnapshot: vi.fn(),sendSelectionToAi: vi.fn(),@@ -93,6 +94,19 @@ function button(label: string) {}describe("QueryEditor extracted context menu", () => {+ it("offers copying the statement at the cursor next to selecting it", async () => {+ const { state, actions, open } = mountMenu("full");+ state.selectedSql = "SELECT 1";+ state.executableSql = "SELECT 1";+ await open();+ const select = button("editor.contextMenu.selectCurrentStatement");+ expect(select).toBeDefined();+ const copy = button("editor.contextMenu.copyCurrentStatement");+ expect(copy).toBeDefined();+ copy.click();+ expect(actions.copyCurrentStatementFromContextMenu).toHaveBeenCalledExactlyOnceWith();+ });+it("keeps primary actions direct and groups clipboard, structure and result operations", async () => {const { state, actions, open } = mountMenu("grouped");state.selectedSql = "SELECT * FROM orders";diff --git a/apps/desktop/src/components/editor/__tests__/QueryEditorSelectCurrentStatement.integration.spec.ts b/apps/desktop/src/components/editor/__tests__/QueryEditorSelectCurrentStatement.integration.spec.tsindex acef7eeec2..5e4f587e3f 100644--- a/apps/desktop/src/components/editor/__tests__/QueryEditorSelectCurrentStatement.integration.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/QueryEditorSelectCurrentStatement.integration.spec.ts@@ -10,7 +10,8 @@ import { useSettingsStore } from "@/stores/settingsStore";import { useConnectionStore } from "@/stores/connectionStore";import type { QueryEditorProps } from "../queryEditorTypes";-vi.mock("@/lib/common/clipboard", () => ({+vi.mock("@/lib/common/clipboard", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@/lib/common/clipboard")>()),copyToClipboard: vi.fn().mockResolvedValue(undefined),readTextFromClipboard: vi.fn().mockResolvedValue(""),}));@@ -30,6 +31,7 @@ async function mountEditor(modelValue: string, overrides: Partial<QueryEditorProsettingsStore.editorSettings.showExecutionTargetPicker = false;settingsStore.editorSettings.executeMode = "current";settingsStore.editorSettings.executeAllOnBlankLine = false;+ settingsStore.editorSettings.sidebarMenuLayout = "full";// 快捷键用显式修饰键(而不是 Mod)书写,让用例在所有平台上确定性地触发,// 与 QueryEditorSearchKeymap.spec.ts 的做法一致。settingsStore.editorSettings.shortcuts.selectCurrentStatement = "Ctrl+Shift+E";@@ -110,6 +112,26 @@ describe("QueryEditor select current statement", () => {expect(selectedText(view)).toBe("SELECT 2");});+ it("copies the statement at the cursor from the context menu without changing the selection (#13261)", async () => {+ const sql = "SELECT 1;\nSELECT 2 FROM t;\nSELECT 3;";+ const { view } = await mountEditor(sql);+ placeCursor(view, sql.indexOf("SELECT 2") + 5);++ // happy-dom has no layout, so the click position resolves to the caret.+ vi.spyOn(EditorView.prototype, "posAtCoords").mockReturnValue(null);+ document.querySelector("[data-query-editor-root]")!.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 10, clientY: 10 }));+ const copyButton = await vi.waitFor(() => {+ const found = [...document.querySelectorAll<HTMLButtonElement>("[data-dbx-context-menu] button")].find((b) => b.textContent?.includes("editor.contextMenu.copyCurrentStatement"));+ expect(found).toBeDefined();+ return found!;+ });+ copyButton.click();++ const { copyToClipboard } = await import("@/lib/common/clipboard");+ await vi.waitFor(() => expect(vi.mocked(copyToClipboard)).toHaveBeenCalledExactlyOnceWith("SELECT 2 FROM t"));+ expect(selectedText(view)).toBe("");+ });+it("leaves the selection untouched when there is no executable statement", async () => {const { view } = await mountEditor("-- only a comment");placeCursor(view, 3);diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 4ad5640d1e..814d3ce56b 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -1614,6 +1614,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Növbəti uyğunluğu əlavə et",selectAllSelectionOccurrences: "Bütün uyğunluqları seç",selectCurrentStatement: "Cari ifadəni seç",+ copyCurrentStatement: "Cari ifadəni kopyala",expandSelectStar: "* işarəsini sütunlarla əvəz et",expandSelectStarUnavailable: "Bu cədvəlin sütunlarını yükləmək mümkün deyil",findReplace: "Tap/əvəz et",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex 19255d877d..f00d8879b0 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -2349,6 +2349,7 @@ export default {addNextSelectionOccurrence: "Add next occurrence",selectAllSelectionOccurrences: "Select all occurrences",selectCurrentStatement: "Select current statement",+ copyCurrentStatement: "Copy current statement",expandSelectStar: "Expand * to columns",expandSelectStarUnavailable: "Unable to load columns for this table",findReplace: "Find/Replace",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex b0555e5ad6..3e3817646b 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -2190,6 +2190,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Añadir siguiente coincidencia",selectAllSelectionOccurrences: "Seleccionar todas las coincidencias",selectCurrentStatement: "Seleccionar la sentencia actual",+ copyCurrentStatement: "Copiar la instrucción actual",expandSelectStar: "Expandir * a columnas",expandSelectStarUnavailable: "No se pudieron cargar las columnas de esta tabla",findReplace: "Buscar/Reemplazar",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 821dea4cfe..1ed9d89059 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -1882,6 +1882,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Tambah kemunculan berikutnya",selectAllSelectionOccurrences: "Pilih semua kemunculan",selectCurrentStatement: "Pilih pernyataan saat ini",+ copyCurrentStatement: "Salin pernyataan saat ini",expandSelectStar: "Perluas * menjadi kolom",expandSelectStarUnavailable: "Tidak dapat memuat kolom untuk tabel ini",findReplace: "Cari/Ganti",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 97a99e333a..63f0848865 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -2099,6 +2099,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Aggiungi occorrenza successiva",selectAllSelectionOccurrences: "Seleziona tutte le occorrenze",selectCurrentStatement: "Seleziona l'istruzione corrente",+ copyCurrentStatement: "Copia l’istruzione corrente",expandSelectStar: "Espandi * in colonne",expandSelectStarUnavailable: "Impossibile caricare le colonne di questa tabella",findReplace: "Trova/Sostituisci",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 98de2da17a..e80a6e598c 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -2118,6 +2118,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "次の出現箇所を選択に追加",selectAllSelectionOccurrences: "すべての出現箇所を選択",selectCurrentStatement: "現在のステートメントを選択",+ copyCurrentStatement: "現在のステートメントをコピー",expandSelectStar: "* を列に展開",expandSelectStarUnavailable: "このテーブルの列を読み込めません",findReplace: "検索/置換",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex dba914caa3..087cf5f1cc 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -2031,6 +2031,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "다음 일치 항목 선택 추가",selectAllSelectionOccurrences: "모든 일치 항목 선택",selectCurrentStatement: "현재 문 선택",+ copyCurrentStatement: "현재 문 복사",expandSelectStar: "*을(를) 열로 확장",expandSelectStarUnavailable: "이 테이블의 열을 불러올 수 없습니다",findReplace: "찾기/바꾸기",diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.tsindex 2b2f1dc0e4..bd49ead14d 100644--- a/apps/desktop/src/i18n/locales/pl.ts+++ b/apps/desktop/src/i18n/locales/pl.ts@@ -1926,6 +1926,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Dodaj następne wystąpienie",selectAllSelectionOccurrences: "Zaznacz wszystkie wystąpienia",selectCurrentStatement: "Zaznacz bieżącą instrukcję",+ copyCurrentStatement: "Kopiuj bieżącą instrukcję",expandSelectStar: "Rozwiń * do listy kolumn",expandSelectStarUnavailable: "Nie można wczytać kolumn tej tabeli",findReplace: "Znajdź i zamień",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex 682db63d4d..71e92c90cd 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -2100,6 +2100,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Adicionar próxima ocorrência",selectAllSelectionOccurrences: "Selecionar todas as ocorrências",selectCurrentStatement: "Selecionar a instrução atual",+ copyCurrentStatement: "Copiar a instrução atual",expandSelectStar: "Expandir * em colunas",expandSelectStarUnavailable: "Não foi possível carregar as colunas desta tabela",findReplace: "Localizar/substituir",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex e0ebea50b7..b902808c46 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -2111,6 +2111,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Добавить следующее вхождение",selectAllSelectionOccurrences: "Выбрать все вхождения",selectCurrentStatement: "Выделить текущую инструкцию",+ copyCurrentStatement: "Копировать текущий оператор",expandSelectStar: "Раскрыть * в столбцы",expandSelectStarUnavailable: "Не удалось загрузить столбцы этой таблицы",findReplace: "Найти/Заменить",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex 429fe959be..4489804b30 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -2271,6 +2271,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "เพิ่มรายการที่พบถัดไป",selectAllSelectionOccurrences: "เลือกทุกตำแหน่งที่พบ",selectCurrentStatement: "เลือก Statement ปัจจุบัน",+ copyCurrentStatement: "คัดลอกคำสั่งปัจจุบัน",expandSelectStar: "ขยาย * เป็นคอลัมน์",expandSelectStarUnavailable: "โหลดคอลัมน์สำหรับตารางนี้ไม่สำเร็จ",findReplace: "ค้นหา/แทนที่",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex 8e97e35660..52e8fabad2 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -1612,6 +1612,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "Sonraki eşleşmeyi ekle",selectAllSelectionOccurrences: "Tüm eşleşmeleri seç",selectCurrentStatement: "Geçerli ifadeyi seç",+ copyCurrentStatement: "Geçerli ifadeyi kopyala",expandSelectStar: "* ifadesini sütunlara genişlet",expandSelectStarUnavailable: "Bu tablonun sütunları yüklenemedi",findReplace: "Bul/Değiştir",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 8fffe2bc53..d5686d025b 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -2282,6 +2282,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "增加下一个选中词",selectAllSelectionOccurrences: "选中所有选中词",selectCurrentStatement: "选中当前语句",+ copyCurrentStatement: "复制当前语句",expandSelectStar: "将 * 展开为字段",expandSelectStarUnavailable: "无法读取该表的字段信息",findReplace: "查找/替换",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex e993ceecc0..c38437760e 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -2100,6 +2100,7 @@ export default withEnglishFallback({addNextSelectionOccurrence: "增加下一個選取詞",selectAllSelectionOccurrences: "選取所有選取詞",selectCurrentStatement: "選取目前語句",+ copyCurrentStatement: "複製當前語句",expandSelectStar: "將 * 展開為欄位",expandSelectStarUnavailable: "無法讀取此資料表的欄位資訊",findReplace: "查找/取代",