feat: add query editor replace shortcut
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -371,6 +371,7 @@ export interface QueryTab {
|
||||
| "cte"
|
||||
| "set-operation"
|
||||
| "aggregation"
|
||||
| "external-source"
|
||||
| "complex-source"
|
||||
| "computed-columns"
|
||||
| "no-table"
|
||||
|
||||
@@ -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*</);
|
||||
});
|
||||
Reference in New Issue
Block a user