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。

feat: add query editor replace shortcut

t8y222e8fece1ca2
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index 952e402b0f..b6513ae2e6 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -148,6 +148,7 @@ const useRegex = ref(false);
const matchCount = ref(0);
const currentMatchIndex = ref(0);
const searchInputRef = ref<HTMLInputElement>();
+const replaceInputRef = ref<HTMLInputElement>();
interface EditorGestureEvent extends Event {
scale?: number;
@@ -315,6 +316,16 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
return true;
},
},
+ {
+ key: "Mod-h",
+ preventDefault: true,
+ run: openReplace,
+ },
+ {
+ key: "Ctrl-h",
+ preventDefault: true,
+ run: openReplace,
+ },
{
key: shortcutToCodeMirrorKey(shortcuts.executeSql),
preventDefault: true,
@@ -1365,6 +1376,16 @@ function openSearch(): boolean {
return true;
}
+function openReplace(): boolean {
+ openSearch();
+ showReplace.value = true;
+ nextTick(() => {
+ replaceInputRef.value?.focus();
+ replaceInputRef.value?.select();
+ });
+ return true;
+}
+
function closeSearch() {
searchVisible.value = false;
showReplace.value = false;
@@ -1504,6 +1525,7 @@ defineExpose({ openSearch });
</div>
<div v-if="showReplace" class="flex items-center gap-0.5">
<input
+ ref="replaceInputRef"
v-model="replaceText"
autocapitalize="off"
autocorrect="off"
@@ -1524,7 +1546,7 @@ defineExpose({ openSearch });
:title="t('editor.search.replaceAll')"
@click="doReplaceAll"
>
- 全部
+ {{ t("editor.search.replaceAll") }}
</button>
</div>
</div>
diff --git a/apps/desktop/src/types/database.ts b/apps/desktop/src/types/database.ts
index 0736e3c698..06ed39f5ea 100644
--- a/apps/desktop/src/types/database.ts
+++ b/apps/desktop/src/types/database.ts
@@ -371,6 +371,7 @@ export interface QueryTab {
| "cte"
| "set-operation"
| "aggregation"
+ | "external-source"
| "complex-source"
| "computed-columns"
| "no-table"
diff --git a/packages/app-tests/queryEditorSearchReplace.test.ts b/packages/app-tests/queryEditorSearchReplace.test.ts
new file mode 100644
index 0000000000..fec9a77551
--- /dev/null
+++ b/packages/app-tests/queryEditorSearchReplace.test.ts
@@ -0,0 +1,18 @@
+import { strict as assert } from "node:assert";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+const source = readFileSync("apps/desktop/src/components/editor/QueryEditor.vue", "utf8");
+
+test("query editor opens replace panel with Mod-H", () => {
+ assert.match(source, /key:\s*"Mod-h"/);
+ assert.match(source, /key:\s*"Ctrl-h"/);
+ assert.match(source, /run:\s*openReplace/);
+ assert.match(source, /showReplace\.value\s*=\s*true/);
+ assert.match(source, /replaceInputRef\.value\?\.focus\(\)/);
+});
+
+test("query editor localizes the replace all button", () => {
+ assert.match(source, /t\("editor\.search\.replaceAll"\)/);
+ assert.doesNotMatch(source, />\s*全部\s*</);
+});