优化功能
This commit is contained in:
@@ -55,8 +55,8 @@
|
|||||||
},
|
},
|
||||||
"topic_20260710-063053_353d579222d3b70b": {
|
"topic_20260710-063053_353d579222d3b70b": {
|
||||||
"stage": 3,
|
"stage": 3,
|
||||||
"userTurns": 3,
|
"userTurns": 4,
|
||||||
"basisHash": "aaae120b1f33c2f2",
|
"basisHash": "aaae120b1f33c2f2",
|
||||||
"updatedAt": 1783668572932
|
"updatedAt": 1783674217586
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,5 +9,6 @@
|
|||||||
"topic_20260710-034033_6432ee6566f7b432": 1783654833341,
|
"topic_20260710-034033_6432ee6566f7b432": 1783654833341,
|
||||||
"topic_20260710-034724_3c6fb29d8d0a4119": 1783655244536,
|
"topic_20260710-034724_3c6fb29d8d0a4119": 1783655244536,
|
||||||
"topic_20260710-054543_5e7c427932aecd7b": 1783662343716,
|
"topic_20260710-054543_5e7c427932aecd7b": 1783662343716,
|
||||||
"topic_20260710-063053_353d579222d3b70b": 1783665053391
|
"topic_20260710-063053_353d579222d3b70b": 1783665053391,
|
||||||
|
"topic_20260710-090003_60717bd90da5ec68": 1783674003004
|
||||||
}
|
}
|
||||||
@@ -47,5 +47,6 @@
|
|||||||
"topic_20260710-034033_6432ee6566f7b432": "auto",
|
"topic_20260710-034033_6432ee6566f7b432": "auto",
|
||||||
"topic_20260710-034724_3c6fb29d8d0a4119": "auto",
|
"topic_20260710-034724_3c6fb29d8d0a4119": "auto",
|
||||||
"topic_20260710-054543_5e7c427932aecd7b": "auto",
|
"topic_20260710-054543_5e7c427932aecd7b": "auto",
|
||||||
"topic_20260710-063053_353d579222d3b70b": "auto"
|
"topic_20260710-063053_353d579222d3b70b": "auto",
|
||||||
|
"topic_20260710-090003_60717bd90da5ec68": "auto"
|
||||||
}
|
}
|
||||||
@@ -47,5 +47,6 @@
|
|||||||
"topic_20260710-034033_6432ee6566f7b432": "我在点击目录树的时候新增文件夹和新建…",
|
"topic_20260710-034033_6432ee6566f7b432": "我在点击目录树的时候新增文件夹和新建…",
|
||||||
"topic_20260710-034724_3c6fb29d8d0a4119": "目录树中鼠标悬浮弹框dropmenu…",
|
"topic_20260710-034724_3c6fb29d8d0a4119": "目录树中鼠标悬浮弹框dropmenu…",
|
||||||
"topic_20260710-054543_5e7c427932aecd7b": "现在在markdown的编辑区域中…",
|
"topic_20260710-054543_5e7c427932aecd7b": "现在在markdown的编辑区域中…",
|
||||||
"topic_20260710-063053_353d579222d3b70b": "这个应用里有一个全局搜索的功能,帮我…"
|
"topic_20260710-063053_353d579222d3b70b": "这个应用里有一个全局搜索的功能,帮我…",
|
||||||
|
"topic_20260710-090003_60717bd90da5ec68": "新的会话"
|
||||||
}
|
}
|
||||||
@@ -334,23 +334,14 @@ fn rename_entry(path: String, new_name: String) -> Result<String, String> {
|
|||||||
fn search_files(
|
fn search_files(
|
||||||
workspace: String,
|
workspace: String,
|
||||||
keyword: String,
|
keyword: String,
|
||||||
case_sensitive: bool,
|
|
||||||
use_regex: bool,
|
|
||||||
whole_word: bool,
|
|
||||||
extensions: Vec<String>,
|
|
||||||
) -> Result<Vec<FileSearchResult>, String> {
|
) -> Result<Vec<FileSearchResult>, String> {
|
||||||
if keyword.is_empty() {
|
if keyword.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern = if use_regex {
|
let pattern = regex::escape(&keyword);
|
||||||
keyword.clone()
|
|
||||||
} else {
|
|
||||||
regex::escape(&keyword)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut builder = regex::RegexBuilder::new(&pattern);
|
let mut builder = regex::RegexBuilder::new(&pattern);
|
||||||
builder.case_insensitive(!case_sensitive);
|
builder.case_insensitive(true);
|
||||||
let re = builder
|
let re = builder
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| format!("正则表达式无效: {}", e))?;
|
.map_err(|e| format!("正则表达式无效: {}", e))?;
|
||||||
@@ -362,8 +353,6 @@ fn search_files(
|
|||||||
workspace_path,
|
workspace_path,
|
||||||
workspace_path,
|
workspace_path,
|
||||||
&re,
|
&re,
|
||||||
whole_word,
|
|
||||||
&extensions,
|
|
||||||
&mut results,
|
&mut results,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -375,8 +364,6 @@ fn walk_dir(
|
|||||||
base: &std::path::Path,
|
base: &std::path::Path,
|
||||||
dir: &std::path::Path,
|
dir: &std::path::Path,
|
||||||
re: &Regex,
|
re: &Regex,
|
||||||
whole_word: bool,
|
|
||||||
extensions: &[String],
|
|
||||||
results: &mut Vec<FileSearchResult>,
|
results: &mut Vec<FileSearchResult>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let entries = fs::read_dir(dir).map_err(|e| format!("无法读取目录: {}", e))?;
|
let entries = fs::read_dir(dir).map_err(|e| format!("无法读取目录: {}", e))?;
|
||||||
@@ -389,14 +376,14 @@ fn walk_dir(
|
|||||||
|
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
walk_dir(base, &path, re, whole_word, extensions, results)?;
|
walk_dir(base, &path, re, results)?;
|
||||||
} else if path.is_file() {
|
} else if path.is_file() {
|
||||||
let ext = path
|
let ext = path
|
||||||
.extension()
|
.extension()
|
||||||
.and_then(|e| e.to_str())
|
.and_then(|e| e.to_str())
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_lowercase();
|
.to_lowercase();
|
||||||
if !extensions.iter().any(|e| e == &ext) {
|
if ext != "md" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,27 +396,10 @@ fn walk_dir(
|
|||||||
let mut matches: Vec<SearchMatch> = Vec::new();
|
let mut matches: Vec<SearchMatch> = Vec::new();
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
let has_match = if whole_word {
|
if !re.is_match(line) {
|
||||||
re.find_iter(line).any(|m| {
|
continue;
|
||||||
let start = m.start();
|
}
|
||||||
let end = m.end();
|
|
||||||
let prev_char = line[..start]
|
|
||||||
.chars()
|
|
||||||
.last()
|
|
||||||
.map(|c| !c.is_alphanumeric() && c != '_')
|
|
||||||
.unwrap_or(true);
|
|
||||||
let next_char = line[end..]
|
|
||||||
.chars()
|
|
||||||
.next()
|
|
||||||
.map(|c| !c.is_alphanumeric() && c != '_')
|
|
||||||
.unwrap_or(true);
|
|
||||||
prev_char && next_char
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
re.is_match(line)
|
|
||||||
};
|
|
||||||
|
|
||||||
if has_match {
|
|
||||||
let column = re
|
let column = re
|
||||||
.find(line)
|
.find(line)
|
||||||
.map(|m| line[..m.start()].chars().count() + 1)
|
.map(|m| line[..m.start()].chars().count() + 1)
|
||||||
@@ -463,7 +433,6 @@ fn walk_dir(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !matches.is_empty() {
|
if !matches.is_empty() {
|
||||||
let relative_path = path
|
let relative_path = path
|
||||||
|
|||||||
@@ -83,10 +83,6 @@ const MAX_SEARCH_HISTORY = 10;
|
|||||||
const SEARCH_DEBOUNCE_MS = 300;
|
const SEARCH_DEBOUNCE_MS = 300;
|
||||||
|
|
||||||
const searchKeyword = ref("");
|
const searchKeyword = ref("");
|
||||||
const searchCaseSensitive = ref(false);
|
|
||||||
const searchUseRegex = ref(false);
|
|
||||||
const searchWholeWord = ref(false);
|
|
||||||
const searchExtensions = ref<string[]>(["md"]);
|
|
||||||
const searchResults = ref<FileSearchResult[]>([]);
|
const searchResults = ref<FileSearchResult[]>([]);
|
||||||
const searchLoading = ref(false);
|
const searchLoading = ref(false);
|
||||||
const searchError = ref("");
|
const searchError = ref("");
|
||||||
@@ -95,21 +91,6 @@ const searchInputRef = ref<HTMLInputElement | null>(null);
|
|||||||
const searchFocusedFile = ref<string | null>(null);
|
const searchFocusedFile = ref<string | null>(null);
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const searchableTypes = [
|
|
||||||
{ label: "Markdown (.md)", value: "md" },
|
|
||||||
{ label: "纯文本 (.txt)", value: "txt" },
|
|
||||||
{ label: "JSON (.json)", value: "json" },
|
|
||||||
{ label: "YAML (.yaml/.yml)", value: "yaml" },
|
|
||||||
{ label: "JavaScript (.js)", value: "js" },
|
|
||||||
{ label: "TypeScript (.ts)", value: "ts" },
|
|
||||||
{ label: "CSS (.css)", value: "css" },
|
|
||||||
{ label: "HTML (.html)", value: "html" },
|
|
||||||
{ label: "XML (.xml)", value: "xml" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const showExtensionDropdown = ref(false);
|
|
||||||
const extensionDropdownRef = ref<HTMLElement | null>(null);
|
|
||||||
|
|
||||||
const totalMatchCount = computed(() => {
|
const totalMatchCount = computed(() => {
|
||||||
return searchResults.value.reduce((sum, f) => sum + f.match_count, 0);
|
return searchResults.value.reduce((sum, f) => sum + f.match_count, 0);
|
||||||
});
|
});
|
||||||
@@ -150,10 +131,6 @@ async function performSearch() {
|
|||||||
const results = await invoke<FileSearchResult[]>("search_files", {
|
const results = await invoke<FileSearchResult[]>("search_files", {
|
||||||
workspace: props.folderPath,
|
workspace: props.folderPath,
|
||||||
keyword,
|
keyword,
|
||||||
caseSensitive: searchCaseSensitive.value,
|
|
||||||
useRegex: searchUseRegex.value,
|
|
||||||
wholeWord: searchWholeWord.value,
|
|
||||||
extensions: searchExtensions.value,
|
|
||||||
});
|
});
|
||||||
searchResults.value = results;
|
searchResults.value = results;
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
@@ -181,18 +158,6 @@ function clearSearch() {
|
|||||||
searchFocusedFile.value = null;
|
searchFocusedFile.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleExtension(ext: string) {
|
|
||||||
const idx = searchExtensions.value.indexOf(ext);
|
|
||||||
if (idx >= 0) {
|
|
||||||
if (searchExtensions.value.length > 1) {
|
|
||||||
searchExtensions.value.splice(idx, 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
searchExtensions.value = [...searchExtensions.value, ext];
|
|
||||||
}
|
|
||||||
triggerSearch();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSearchKeydown(e: KeyboardEvent) {
|
function handleSearchKeydown(e: KeyboardEvent) {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
clearSearch();
|
clearSearch();
|
||||||
@@ -231,13 +196,10 @@ function activateSearch() {
|
|||||||
|
|
||||||
function highlightMatchText(text: string): string {
|
function highlightMatchText(text: string): string {
|
||||||
const keyword = searchKeyword.value.trim();
|
const keyword = searchKeyword.value.trim();
|
||||||
if (!keyword || searchUseRegex.value) {
|
if (!keyword) return escapeHtml(text);
|
||||||
return escapeHtml(text);
|
|
||||||
}
|
|
||||||
const escaped = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
const escaped = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
try {
|
try {
|
||||||
const flags = searchCaseSensitive.value ? "g" : "gi";
|
const re = new RegExp(`(${escaped})`, "gi");
|
||||||
const re = new RegExp(`(${escaped})`, flags);
|
|
||||||
return escapeHtml(text).replace(re, "<mark class='search-highlight'>$1</mark>");
|
return escapeHtml(text).replace(re, "<mark class='search-highlight'>$1</mark>");
|
||||||
} catch {
|
} catch {
|
||||||
return escapeHtml(text);
|
return escapeHtml(text);
|
||||||
@@ -251,21 +213,7 @@ function escapeHtml(text: string): string {
|
|||||||
.replace(/>/g, ">");
|
.replace(/>/g, ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeExtensionDropdown(e: MouseEvent) {
|
watch(searchKeyword, () => {
|
||||||
if (extensionDropdownRef.value && !extensionDropdownRef.value.contains(e.target as Node)) {
|
|
||||||
showExtensionDropdown.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(showExtensionDropdown, (open) => {
|
|
||||||
if (open) {
|
|
||||||
setTimeout(() => document.addEventListener("click", closeExtensionDropdown), 0);
|
|
||||||
} else {
|
|
||||||
document.removeEventListener("click", closeExtensionDropdown);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch([searchKeyword, searchCaseSensitive, searchUseRegex, searchWholeWord], () => {
|
|
||||||
triggerSearch();
|
triggerSearch();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -703,64 +651,7 @@ function handleCreateRootFile() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 搜索选项 -->
|
|
||||||
<div class="flex items-center gap-2 mt-2 flex-wrap">
|
|
||||||
<button
|
|
||||||
class="search-option-btn"
|
|
||||||
:class="{ 'search-option-active': searchCaseSensitive }"
|
|
||||||
title="区分大小写"
|
|
||||||
@click="searchCaseSensitive = !searchCaseSensitive"
|
|
||||||
>
|
|
||||||
Aa
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="search-option-btn"
|
|
||||||
:class="{ 'search-option-active': searchUseRegex }"
|
|
||||||
title="正则表达式"
|
|
||||||
@click="searchUseRegex = !searchUseRegex"
|
|
||||||
>
|
|
||||||
.*
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="search-option-btn"
|
|
||||||
:class="{ 'search-option-active': searchWholeWord }"
|
|
||||||
title="全词匹配"
|
|
||||||
@click="searchWholeWord = !searchWholeWord"
|
|
||||||
>
|
|
||||||
<i class="ri-font-size"></i>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- 文件类型下拉 -->
|
|
||||||
<div ref="extensionDropdownRef" class="relative">
|
|
||||||
<button
|
|
||||||
class="search-option-btn flex items-center gap-1"
|
|
||||||
@click="showExtensionDropdown = !showExtensionDropdown"
|
|
||||||
title="文件类型"
|
|
||||||
>
|
|
||||||
<span class="text-[10px]">.{{ searchExtensions.join(', .') }}</span>
|
|
||||||
<i class="ri-arrow-down-s-line text-[9px]"></i>
|
|
||||||
</button>
|
|
||||||
<div
|
|
||||||
v-if="showExtensionDropdown"
|
|
||||||
class="search-ext-dropdown absolute top-full left-0 mt-1 bg-[var(--app-surface)] border border-[var(--app-border)] rounded-md shadow-lg z-30 py-1 min-w-[150px] max-h-52 overflow-y-auto"
|
|
||||||
@click.stop
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
v-for="type in searchableTypes"
|
|
||||||
:key="type.value"
|
|
||||||
class="flex items-center gap-2 px-3 py-1.5 text-xs cursor-pointer hover:bg-[var(--app-hover)]"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
:checked="searchExtensions.includes(type.value)"
|
|
||||||
class="w-3 h-3 accent-[var(--app-accent)]"
|
|
||||||
@change="toggleExtension(type.value)"
|
|
||||||
/>
|
|
||||||
{{ type.label }}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 搜索结果区域 -->
|
<!-- 搜索结果区域 -->
|
||||||
@@ -776,7 +667,7 @@ function handleCreateRootFile() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Empty prompt / history -->
|
<!-- Empty prompt / history -->
|
||||||
<div v-else-if="!searchKeyword.trim()" class="flex flex-col py-4 px-1">
|
<div v-else-if="!searchKeyword.trim()" class="flex flex-col px-1">
|
||||||
<template v-if="searchHistory.length > 0">
|
<template v-if="searchHistory.length > 0">
|
||||||
<p class="text-[10px] text-[var(--app-subtle)] px-2 mb-2 uppercase tracking-wider">最近搜索</p>
|
<p class="text-[10px] text-[var(--app-subtle)] px-2 mb-2 uppercase tracking-wider">最近搜索</p>
|
||||||
<button
|
<button
|
||||||
@@ -1765,34 +1656,6 @@ function handleCreateRootFile() {
|
|||||||
|
|
||||||
/* ── Search view ──────────────────────────────────────────────── */
|
/* ── Search view ──────────────────────────────────────────────── */
|
||||||
|
|
||||||
.search-option-btn {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
height: 24px;
|
|
||||||
min-width: 24px;
|
|
||||||
padding: 0 6px;
|
|
||||||
font-size: 11px;
|
|
||||||
font-weight: 500;
|
|
||||||
border-radius: 4px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
background: transparent;
|
|
||||||
color: var(--app-subtle);
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.15s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-option-btn:hover {
|
|
||||||
background: var(--app-hover);
|
|
||||||
color: var(--app-text-soft);
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-option-active {
|
|
||||||
background: color-mix(in srgb, var(--app-accent) 15%, transparent);
|
|
||||||
color: var(--app-accent);
|
|
||||||
border-color: color-mix(in srgb, var(--app-accent) 30%, transparent);
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-file-header {
|
.search-file-header {
|
||||||
color: var(--app-text-soft);
|
color: var(--app-text-soft);
|
||||||
}
|
}
|
||||||
@@ -1815,8 +1678,4 @@ function handleCreateRootFile() {
|
|||||||
.search-history-item {
|
.search-history-item {
|
||||||
color: var(--app-text-soft);
|
color: var(--app-text-soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-ext-dropdown {
|
|
||||||
backdrop-filter: blur(12px);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user