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 whole-word matching to the find panel
李子凡709a11196930
diff --git a/apps/desktop/src/components/editor/EditorSearchPanel.vue b/apps/desktop/src/components/editor/EditorSearchPanel.vueindex 2f5a2b625d..7236745138 100644--- a/apps/desktop/src/components/editor/EditorSearchPanel.vue+++ b/apps/desktop/src/components/editor/EditorSearchPanel.vue@@ -29,6 +29,7 @@ const replaceText = ref("");const showReplace = ref(false);const caseSensitive = ref(false);const useRegex = ref(false);+const wholeWord = ref(false);const matchCount = ref(0);const currentMatchIndex = ref(0);const searchInputRef = ref<HTMLInputElement>();@@ -78,6 +79,7 @@ function dispatchSearchQuery() {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,replace: replaceText.value,});v.dispatch({ effects: setSearchQuery.of(q) });@@ -131,6 +133,7 @@ function collectScopedMatches(v: EditorView, limit = Number.POSITIVE_INFINITY) {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!q.valid) return null;return collectEditorSearchMatches(q, v.state, searchScopeFrom, searchScopeTo, limit);@@ -142,6 +145,7 @@ function collectAllMatches(v: EditorView, limit = Number.POSITIVE_INFINITY) {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!query.valid) return [];return collectEditorSearchMatches(query, v.state, searchScopeFrom ?? 0, searchScopeTo ?? v.state.doc.length, limit);@@ -153,6 +157,7 @@ function* iterateAllMatches(v: EditorView): Generator<EditorSearchMatch> {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!query.valid) return;const from = searchScopeFrom ?? 0;@@ -203,6 +208,7 @@ function updateMatchInfo(autoSelect = false) {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!q.valid) return;const selFrom = v.state.selection.main.from;@@ -218,6 +224,7 @@ function updateMatchInfo(autoSelect = false) {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!q.valid) {matchCount.value = 0;@@ -405,6 +412,7 @@ function doReplace() {search: searchText.value,caseSensitive: caseSensitive.value,useRegex: useRegex.value,+ wholeWord: wholeWord.value,});if (!q.valid) return;const iter = q.getCursor(v.state);@@ -470,7 +478,7 @@ function onSearchKeydown(e: KeyboardEvent) {}}-watch([searchText, caseSensitive, useRegex], () => {+watch([searchText, caseSensitive, useRegex, wholeWord], () => {if (searchVisible.value) scheduleSearchUpdate(true);});@@ -522,6 +530,14 @@ defineExpose({>Aa</button>+ <button+ class="flex h-6 min-w-7 items-center justify-center rounded px-1.5 text-xs font-medium transition-colors hover:bg-accent hover:text-foreground"+ :class="wholeWord ? 'bg-accent text-foreground' : 'text-muted-foreground'"+ :title="t('editor.search.wholeWord')"+ @click="wholeWord = !wholeWord"+ >+ W+ </button><buttonclass="mr-1 flex h-6 min-w-7 items-center justify-center rounded px-1.5 font-mono text-xs transition-colors hover:bg-accent hover:text-foreground":class="useRegex ? 'bg-accent text-foreground' : 'text-muted-foreground'"diff --git a/apps/desktop/src/components/editor/__tests__/EditorSearchPanel.wholeWord.spec.ts b/apps/desktop/src/components/editor/__tests__/EditorSearchPanel.wholeWord.spec.tsnew file mode 100644index 0000000000..9132fde71f--- /dev/null+++ b/apps/desktop/src/components/editor/__tests__/EditorSearchPanel.wholeWord.spec.ts@@ -0,0 +1,108 @@+// @vitest-environment happy-dom++import { EditorState } from "@codemirror/state";+import { EditorView } from "@codemirror/view";+import { createApp, defineComponent, h, nextTick, type App } from "vue";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++vi.mock("vue-i18n", () => ({+ useI18n: () => ({ t: (key: string) => key }),+}));++vi.mock("@/stores/settingsStore", () => ({+ useSettingsStore: () => ({+ editorSettings: { regexMaxMatchCount: 1000 },+ }),+}));++import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";++const mountedApps: Array<{ app: App; host: HTMLElement }> = [];++beforeEach(() => {+ vi.useFakeTimers();+});++afterEach(() => {+ for (const { app, host } of mountedApps.splice(0)) {+ app.unmount();+ host.remove();+ }+ vi.useRealTimers();+});++async function mountPanel(doc: string) {+ const view = new EditorView({+ parent: document.createElement("div"),+ state: EditorState.create({ doc }),+ });++ let instance: { openSearch: () => boolean } | null = null;+ const host = document.createElement("div");+ document.body.append(host);+ const app = createApp(+ defineComponent({+ setup() {+ return () =>+ h(EditorSearchPanel, {+ view,+ ref: (el) => {+ instance = el as unknown as { openSearch: () => boolean };+ },+ });+ },+ }),+ );+ app.mount(host);+ mountedApps.push({ app, host });++ instance!.openSearch();+ await nextTick();+ return { host, view };+}++function wordToggle(host: HTMLElement): HTMLButtonElement {+ const button = host.querySelector<HTMLButtonElement>(`button[title="editor.search.wholeWord"]`);+ if (!button) throw new Error("whole-word toggle is missing from the find panel");+ return button;+}++describe("EditorSearchPanel whole-word toggle (issue #13287)", () => {+ it("narrows a literal search from every substring hit to whole words only", async () => {+ const { host, view } = await mountPanel("user_id, id, identity");++ const input = host.querySelector<HTMLInputElement>("input")!;+ input.value = "id";+ input.dispatchEvent(new Event("input"));+ await vi.advanceTimersByTimeAsync(1000);+ await nextTick();+ // Substring search hits user_id, id and identity.+ expect(host.textContent).toContain("1/3");++ wordToggle(host).click();+ await nextTick();+ await vi.advanceTimersByTimeAsync(1000);+ await nextTick();++ expect(wordToggle(host).classList.contains("bg-accent")).toBe(true);+ expect(host.textContent).toContain("1/1");++ view.destroy();+ });++ it("keeps the toggle off by default so existing searches are unchanged", async () => {+ const { host, view } = await mountPanel("identity");++ expect(wordToggle(host).classList.contains("bg-accent")).toBe(false);++ const input = host.querySelector<HTMLInputElement>("input")!;+ input.value = "id";+ input.dispatchEvent(new Event("input"));+ await vi.advanceTimersByTimeAsync(1000);+ await nextTick();++ expect(host.textContent).toContain("1/1");++ view.destroy();+ });+});diff --git a/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts b/apps/desktop/src/i18n/__tests__/featureMessages.spec.tsindex be5d0f22b7..475c7057ee 100644--- a/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts+++ b/apps/desktop/src/i18n/__tests__/featureMessages.spec.ts@@ -56,6 +56,7 @@ const FEATURE_MESSAGES: FeatureMessages[] = [translated: true,},{ feature: "plugin AI conversation", keys: ["ai.pluginHttpModelOnly", "ai.pluginWelcome", "ai.pluginFollowUp"] },+ { feature: "editor find whole word (#13287)", keys: ["editor.search.wholeWord"], translated: true },{ feature: "quick open", keys: ["quickOpen.*", "settings.shortcutGlobalSearch"] },{feature: "editor tab context menu",diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 4b97b9d3e3..84e05b2b60 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -1650,6 +1650,7 @@ export default withEnglishFallback({searchFailed: "Axtarış uğursuz oldu və ya vaxtı bitdi. İfadəni sadələşdirib yenidən cəhd edin.",caseSensitive: "Böyük və kiçik hərflərə həssas",regex: "Müntəzəm ifadə",+ wholeWord: "Bütöv söz",collapseReplace: "Əvəzetməni yığ",expandReplace: "Əvəzetməni genişləndir",prevMatch: "Əvvəlki (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex b8d7fb1b35..bbea9e19cc 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -2385,6 +2385,7 @@ export default {searchFailed: "Search failed or timed out. Simplify the expression and try again.",caseSensitive: "Case sensitive",regex: "Regular expression",+ wholeWord: "Whole word",collapseReplace: "Collapse replace",expandReplace: "Expand replace",prevMatch: "Previous (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex e692cce5b8..29b9836a04 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -2210,6 +2210,7 @@ export default withEnglishFallback({searchFailed: "La búsqueda falló o agotó el tiempo. Simplifica la expresión e inténtalo de nuevo.",caseSensitive: "Distinguir mayúsculas",regex: "Expresión regular",+ wholeWord: "Palabra completa",collapseReplace: "Contraer reemplazo",expandReplace: "Expandir reemplazo",prevMatch: "Anterior (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 614c5eaee1..a238d3ea82 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -1918,6 +1918,7 @@ export default withEnglishFallback({searchFailed: "Pencarian gagal atau kehabisan waktu. Sederhanakan ekspresi dan coba lagi.",caseSensitive: "Case sensitive",regex: "Ekspresi reguler",+ wholeWord: "Kata utuh",collapseReplace: "Ciutkan ganti",expandReplace: "Perluas ganti",prevMatch: "Sebelumnya (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex c43bf450f4..bb8d7fba9e 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -2119,6 +2119,7 @@ export default withEnglishFallback({searchFailed: "Ricerca non riuscita o scaduta. Semplifica l’espressione e riprova.",caseSensitive: "Maiuscole/Minuscole",regex: "Espressione regolare",+ wholeWord: "Parola intera",collapseReplace: "Comprimi sostituzione",expandReplace: "Espandi sostituzione",prevMatch: "Precedente (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex d8e993dc11..7bef761ac9 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -2138,6 +2138,7 @@ export default withEnglishFallback({searchFailed: "検索に失敗したかタイムアウトしました。式を簡略化して再試行してください。",caseSensitive: "大文字/小文字を区別",regex: "正規表現",+ wholeWord: "単語単位",collapseReplace: "置換を折りたたむ",expandReplace: "置換を展開",prevMatch: "前へ (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex 34b2d7c732..08b89c7d32 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -2068,6 +2068,7 @@ export default withEnglishFallback({searchFailed: "검색에 실패했거나 시간이 초과되었습니다. 표현식을 간단히 하고 다시 시도하세요.",caseSensitive: "대소문자 구분",regex: "정규 표현식",+ wholeWord: "단어 단위",collapseReplace: "바꾸기 접기",expandReplace: "바꾸기 펼치기",prevMatch: "이전 (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.tsindex b14afdd4cd..1b2979d4ec 100644--- a/apps/desktop/src/i18n/locales/pl.ts+++ b/apps/desktop/src/i18n/locales/pl.ts@@ -1961,6 +1961,7 @@ export default withEnglishFallback({replaceAll: "Zamień wszystkie",caseSensitive: "Uwzględniaj wielkość liter",regex: "Wyrażenie regularne",+ wholeWord: "Całe słowo",collapseReplace: "Zwiń pole zamiany",expandReplace: "Rozwiń pole zamiany",prevMatch: "Poprzednie (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex 6b7e3bae3e..42d2aa5644 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -2120,6 +2120,7 @@ export default withEnglishFallback({searchFailed: "A busca falhou ou excedeu o tempo. Simplifique a expressão e tente novamente.",caseSensitive: "Diferenciar maiúsculas/minúsculas",regex: "Expressão regular",+ wholeWord: "Palavra inteira",collapseReplace: "Recolher substituição",expandReplace: "Expandir substituição",prevMatch: "Anterior (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 44c8dc78ea..78eee031c6 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -2147,6 +2147,7 @@ export default withEnglishFallback({searchFailed: "Поиск не выполнен или превышено время ожидания. Упростите выражение и повторите попытку.",caseSensitive: "Учитывать регистр",regex: "Регулярное выражение",+ wholeWord: "Только слово целиком",collapseReplace: "Свернуть замену",expandReplace: "Развернуть замену",prevMatch: "Предыдущее (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex b2aa6cc36a..fec95f42e0 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -2306,6 +2306,7 @@ export default withEnglishFallback({replaceAll: "แทนที่ทั้งหมด",caseSensitive: "คำนึงถึงตัวพิมพ์เล็กใหญ่",regex: "Regular Expression",+ wholeWord: "ทั้งคำ",collapseReplace: "ยุบการแทนที่",expandReplace: "ขยายการแทนที่",prevMatch: "ก่อนหน้า (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex 4d44283da5..9243cc2ba7 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -1648,6 +1648,7 @@ export default withEnglishFallback({searchFailed: "Arama başarısız oldu veya zaman aşımına uğradı. İfadeyi basitleştirip tekrar deneyin.",caseSensitive: "Büyük/küçük harfe duyarlı",regex: "Düzenli ifade",+ wholeWord: "Tam kelime",collapseReplace: "Değiştirmeyi daralt",expandReplace: "Değiştirmeyi genişlet",prevMatch: "Önceki (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 067f27a414..607f459cbf 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -2318,6 +2318,7 @@ export default withEnglishFallback({searchFailed: "搜索失败或超时,请简化表达式后重试。",caseSensitive: "区分大小写",regex: "正则表达式",+ wholeWord: "全词匹配",collapseReplace: "收起替换",expandReplace: "展开替换",prevMatch: "上一个 (Shift+Enter)",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 42978c3789..2ecb66f640 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -2120,6 +2120,7 @@ export default withEnglishFallback({searchFailed: "搜尋失敗或逾時,請簡化運算式後重試。",caseSensitive: "區分大小寫",regex: "正規表示式",+ wholeWord: "全字匹配",collapseReplace: "收起取代",expandReplace: "展開取代",prevMatch: "上一個 (Shift+Enter)",diff --git a/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts b/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.tsindex f876ad0f75..3d376c8a6e 100644--- a/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts+++ b/apps/desktop/src/lib/__tests__/editor/editorSearchQuery.spec.ts@@ -64,6 +64,29 @@ describe("editorSearchQuery", () => {expect(countEditorSearchMatches(query, state, 0, state.doc.length)).toEqual({ count: 50000, currentIndex: 0 });});+ it("defaults whole-word matching to off", () => {+ const state = EditorState.create({ doc: "cat concat cathedral" });+ const query = createEditorSearchQuery({ search: "cat", caseSensitive: false, useRegex: false });++ expect(countEditorSearchMatches(query, state, 0, state.doc.length)).toEqual({ count: 3, currentIndex: 0 });+ });++ it("matches whole words only in literal mode", () => {+ const state = EditorState.create({ doc: "cat concat cathedral" });+ const query = createEditorSearchQuery({ search: "cat", caseSensitive: true, useRegex: false, wholeWord: true });++ expect(collectEditorSearchMatches(query, state, 0, state.doc.length)).toEqual([{ from: 0, to: 3 }]);+ });++ it("combines whole-word matching with regular expressions", () => {+ // @codemirror/search applies a word-boundary test to regex cursors too, so the+ // toggle composes with useRegex instead of being disabled in regex mode.+ const state = EditorState.create({ doc: "cat concat cathedral" });+ const query = createEditorSearchQuery({ search: "cat+", caseSensitive: true, useRegex: true, wholeWord: true });++ expect(collectEditorSearchMatches(query, state, 0, state.doc.length)).toEqual([{ from: 0, to: 3 }]);+ });+it("keeps replacement collection uncapped", () => {const state = EditorState.create({ doc: Array.from({ length: 1001 }, () => "x").join(" ") });const query = createEditorSearchQuery({ search: "x", caseSensitive: true, useRegex: false });diff --git a/apps/desktop/src/lib/editor/editorSearchQuery.ts b/apps/desktop/src/lib/editor/editorSearchQuery.tsindex 4abadcd6da..10c59d1138 100644--- a/apps/desktop/src/lib/editor/editorSearchQuery.ts+++ b/apps/desktop/src/lib/editor/editorSearchQuery.ts@@ -6,6 +6,7 @@ export interface EditorSearchQueryOptions {replace?: string;caseSensitive: boolean;useRegex: boolean;+ wholeWord?: boolean;}export function createEditorSearchQuery(options: EditorSearchQueryOptions): SearchQuery {@@ -15,6 +16,7 @@ export function createEditorSearchQuery(options: EditorSearchQueryOptions): SearcaseSensitive: options.caseSensitive,regexp: options.useRegex,literal: !options.useRegex,+ wholeWord: options.wholeWord ?? false,});}