dsh-gufa-code 1.3.62 → 1.3.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,7 @@ dsh plugin add dsh-gufa-code
41
41
  - Monaco 编辑器(离线随包分发,无需联网下载);
42
42
  - 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
43
43
  - 保存走磁盘版本冲突检测 + 原子写;未保存标记;
44
- - **全局搜索**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则;结果按文件分组、高亮匹配,点击直接跳到文件对应行列;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;
44
+ - **全局搜索 / 替换**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则、包含/排除文件(glob);结果按文件分组、高亮匹配,点击跳转行列;替换栏支持保留大小写(AB)、全部替换(需确认)、按文件替换(悬停文件头铅笔)、按单行匹配替换与忽略(悬停结果行);替换前会自动保存未落盘的编辑器内容;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;摸鱼悬浮窗里同样可用;
45
45
  - 资源管理器右键:新建 / 重命名 / 删除 / 复制 / 粘贴 / 打开所在文件夹 / 两文件对比;
46
46
  - **从 Finder 粘贴/拖入文件**:系统剪贴板里复制的文件可直接 ⌘V 粘进资源管理器(写入选中的目录,重名自动加「副本」),也可从 Finder 直接拖进文件树;
47
47
  - **粘贴文件到聊天框 = @引用**:在 Finder 复制文件后在右侧对话输入框 ⌘V,会自动匹配项目内同名同内容文件并插入 `@相对路径` 引用(图片仍按 DSH 默认附件处理);
package/client.js CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.62'
19
+ G.BUILD = '1.3.64'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -199,9 +199,28 @@ const DICT_ZH = {
199
199
  'search.searching': '搜索中…',
200
200
  'search.idle': '输入关键字搜索整个项目',
201
201
  'search.noResult': '没有找到匹配结果',
202
- 'search.summary': '{count} 个结果 · {files} 个文件',
202
+ 'search.summary': '{files} 个文件中有 {count} 个结果',
203
203
  'search.truncated': '结果过多已截断,请缩小范围',
204
204
  'search.error': '搜索失败',
205
+ 'search.replaceToggle': '显示/隐藏替换',
206
+ 'search.include': '包含的文件',
207
+ 'search.exclude': '排除的文件',
208
+ 'search.includePlaceholder': '例如 *.js, src/**',
209
+ 'search.excludePlaceholder': '例如 **/*.min.js, test/**',
210
+ 'search.preserveCase': '保留大小写(AB)',
211
+ 'search.replaceOne': '替换此匹配',
212
+ 'search.dismiss': '忽略此匹配',
213
+ 'search.openInEditor': '在编辑器中打开',
214
+ 'search.stale': '匹配位置已变化,已重新搜索',
215
+ 'search.replacePlaceholder': '替换为…',
216
+ 'search.replaceAll': '全部替换',
217
+ 'search.replaceThisFile': '替换此文件',
218
+ 'search.replacing': '替换中…',
219
+ 'search.replaced': '已替换 {count} 处({files} 个文件)',
220
+ 'search.confirmReplace': '确定替换 {count} 处({files} 个文件)?直接写文件,编辑器撤销无效。',
221
+ 'search.confirmYes': '确定替换',
222
+ 'search.confirmNo': '取消',
223
+ 'search.replaceError': '替换失败',
205
224
  'explorer.empty': '目录为空',
206
225
  'explorer.newFile': '新建文件',
207
226
  'explorer.newFolder': '新建文件夹',
@@ -431,9 +450,28 @@ const DICT_EN = {
431
450
  'search.searching': 'Searching…',
432
451
  'search.idle': 'Type a keyword to search the whole project',
433
452
  'search.noResult': 'No matches found',
434
- 'search.summary': '{count} results · {files} files',
453
+ 'search.summary': '{count} results in {files} files',
435
454
  'search.truncated': 'Too many results, truncated — narrow the query',
436
455
  'search.error': 'Search failed',
456
+ 'search.replaceToggle': 'Show / hide replace',
457
+ 'search.include': 'files to include',
458
+ 'search.exclude': 'files to exclude',
459
+ 'search.includePlaceholder': 'e.g. *.js, src/**',
460
+ 'search.excludePlaceholder': 'e.g. **/*.min.js, test/**',
461
+ 'search.preserveCase': 'Preserve case (AB)',
462
+ 'search.replaceOne': 'Replace this match',
463
+ 'search.dismiss': 'Dismiss this match',
464
+ 'search.openInEditor': 'Open in editor',
465
+ 'search.stale': 'Match moved; search refreshed',
466
+ 'search.replacePlaceholder': 'Replace with…',
467
+ 'search.replaceAll': 'Replace all',
468
+ 'search.replaceThisFile': 'Replace in this file',
469
+ 'search.replacing': 'Replacing…',
470
+ 'search.replaced': 'Replaced {count} occurrences ({files} files)',
471
+ 'search.confirmReplace': 'Replace {count} occurrences in {files} files? This writes files directly; editor undo will not work.',
472
+ 'search.confirmYes': 'Replace',
473
+ 'search.confirmNo': 'Cancel',
474
+ 'search.replaceError': 'Replace failed',
437
475
  'explorer.empty': 'Folder is empty',
438
476
  'explorer.newFile': 'New file',
439
477
  'explorer.newFolder': 'New folder',
@@ -1705,6 +1743,35 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1705
1743
  .gufa-search-line{flex:0 0 auto;min-width:24px;text-align:right;font:11px ui-monospace,Menlo,Consolas,monospace;opacity:.65}
1706
1744
  .gufa-search-text{flex:1 1 auto;min-width:0;font:11.5px ui-monospace,Menlo,Consolas,monospace;white-space:pre;overflow:hidden;text-overflow:ellipsis}
1707
1745
  .gufa-search-hit{background:rgba(192,57,43,.38);color:var(--gufa-text);border-radius:2px;padding:0 1px}
1746
+ .gufa-search-replace-row{margin-top:0}
1747
+ .gufa-search-actions{display:flex;align-items:center;gap:6px;margin-top:6px}
1748
+ .gufa-search-action{height:24px;padding:0 9px;border-radius:6px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);color:var(--gufa-text);font-size:11.5px;cursor:pointer}
1749
+ .gufa-search-action:hover:not(:disabled){border-color:var(--gufa-accent)}
1750
+ .gufa-search-action:disabled{opacity:.5;cursor:default}
1751
+ .gufa-search-action[data-primary]{background:var(--gufa-accent);border-color:var(--gufa-accent);color:#fff}
1752
+ .gufa-search-confirm{margin:6px 8px 0;padding:7px 9px;border-radius:7px;border:1px solid var(--gufa-accent);background:color-mix(in srgb, var(--gufa-accent) 12%, transparent);font-size:11.5px;line-height:1.55;color:var(--gufa-text)}
1753
+ .gufa-search-confirm-actions{display:flex;justify-content:flex-end;gap:6px;margin-top:6px}
1754
+ .gufa-search-notice{margin:6px 8px 0;padding:5px 9px;border-radius:7px;font-size:11.5px;color:var(--dsw-alias-state-success-primary);border:1px solid color-mix(in srgb, var(--dsw-alias-state-success-primary) 45%, transparent)}
1755
+ .gufa-search-error{margin:6px 8px 0;padding:5px 9px;border-radius:7px;font-size:11.5px;color:var(--dsw-alias-state-error-primary);border:1px solid color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent)}
1756
+ .gufa-search-file-replace{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-left:2px;border-radius:4px;color:var(--gufa-text-dim);cursor:pointer}
1757
+ .gufa-search-file-replace:hover{background:var(--gufa-active);color:var(--gufa-text)}
1758
+ .gufa-search-file-replace{opacity:0;transition:opacity .12s ease}
1759
+ .gufa-search-file-head:hover .gufa-search-file-replace,.gufa-search-file-head:focus-within .gufa-search-file-replace{opacity:1}
1760
+ .gufa-search-match{min-height:23px;align-items:center}
1761
+ .gufa-search-match-actions{display:none;flex:0 0 auto;align-items:center;gap:4px;margin-left:auto}
1762
+ .gufa-search-match:hover .gufa-search-match-actions,.gufa-search-match:focus-within .gufa-search-match-actions{display:flex}
1763
+ .gufa-search-row-action{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:4px;color:var(--gufa-text-dim);cursor:pointer}
1764
+ .gufa-search-row-action:hover{background:var(--gufa-active);color:var(--gufa-text)}
1765
+ .gufa-search-filter{display:flex;flex-direction:column;gap:3px;margin-top:5px}
1766
+ .gufa-search-filter-label{font-size:10.5px;color:var(--gufa-text-dim)}
1767
+ .gufa-search-filter-input{width:100%;height:24px;padding:0 8px;border-radius:6px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);color:var(--gufa-text);font-size:11.5px;outline:none}
1768
+ .gufa-search-filter-input:focus{border-color:var(--gufa-accent)}
1769
+ .gufa-search-filter-input::placeholder{color:var(--gufa-text-dim)}
1770
+ .gufa-search-summarybar{display:flex;align-items:center;gap:8px}
1771
+ .gufa-search-summarybar .gufa-search-summary{flex:1 1 auto;margin-left:0}
1772
+ .gufa-search-summarybar .gufa-search-link{flex:0 0 auto}
1773
+ .gufa-search-link{border:0;background:transparent;color:var(--gufa-accent);font-size:11px;cursor:pointer;padding:0}
1774
+ .gufa-search-link:hover{text-decoration:underline}
1708
1775
 
1709
1776
  .gufa-tree-chevron{width:14px;flex:0 0 auto;opacity:.7;display:flex;align-items:center;justify-content:center}
1710
1777
  .gufa-tree-icon{width:15px;flex:0 0 auto;opacity:.85;display:flex;align-items:center;justify-content:center}
@@ -7290,12 +7357,22 @@ G.SearchPanel = function SearchPanel(props) {
7290
7357
  const t = G.useT()
7291
7358
  const root = props.root
7292
7359
  const [query, setQuery] = useState('')
7360
+ const [replacement, setReplacement] = useState('')
7293
7361
  const [caseSensitive, setCaseSensitive] = useState(false)
7294
7362
  const [regex, setRegex] = useState(false)
7363
+ const [preserveCase, setPreserveCase] = useState(false)
7364
+ const [includeText, setIncludeText] = useState('')
7365
+ const [excludeText, setExcludeText] = useState('')
7366
+ const [replaceOpen, setReplaceOpen] = useState(false)
7295
7367
  const [status, setStatus] = useState('idle')
7296
7368
  const [result, setResult] = useState(null)
7297
7369
  const [error, setError] = useState('')
7298
7370
  const [collapsed, setCollapsed] = useState({})
7371
+ const [ignored, setIgnored] = useState(() => new Set())
7372
+ const [confirming, setConfirming] = useState(null)
7373
+ const [replacing, setReplacing] = useState(false)
7374
+ const [replaceError, setReplaceError] = useState('')
7375
+ const [notice, setNotice] = useState('')
7299
7376
  const inputRef = useRef(null)
7300
7377
  const requestRef = useRef(0)
7301
7378
 
@@ -7324,13 +7401,20 @@ G.SearchPanel = function SearchPanel(props) {
7324
7401
  setStatus('loading')
7325
7402
  setError('')
7326
7403
  try {
7327
- const value = await G.api('fs.search', {
7404
+ const found = await G.api('fs.search', {
7328
7405
  root,
7329
7406
  query: text,
7330
- options: { caseSensitive, regex, maxFiles: 200, maxMatches: 500 },
7407
+ options: {
7408
+ caseSensitive,
7409
+ regex,
7410
+ include: includeText,
7411
+ exclude: excludeText,
7412
+ maxFiles: 200,
7413
+ maxMatches: 500,
7414
+ },
7331
7415
  })
7332
7416
  if (seq !== requestRef.current) return
7333
- setResult(value)
7417
+ setResult(found)
7334
7418
  setStatus('ready')
7335
7419
  } catch (err) {
7336
7420
  if (seq !== requestRef.current) return
@@ -7338,7 +7422,7 @@ G.SearchPanel = function SearchPanel(props) {
7338
7422
  setError(G.errorText(err))
7339
7423
  setStatus('error')
7340
7424
  }
7341
- }, [root, caseSensitive, regex])
7425
+ }, [root, caseSensitive, regex, includeText, excludeText])
7342
7426
 
7343
7427
  /* 输入防抖搜索(回车立即搜索) */
7344
7428
  useEffect(() => {
@@ -7354,6 +7438,11 @@ G.SearchPanel = function SearchPanel(props) {
7354
7438
  return () => window.clearTimeout(timer)
7355
7439
  }, [query, runSearch, root])
7356
7440
 
7441
+ /* 搜索条件变化后,之前「忽略的匹配」不再适用 */
7442
+ useEffect(() => {
7443
+ setIgnored(new Set())
7444
+ }, [query, caseSensitive, regex, includeText, excludeText])
7445
+
7357
7446
  /* 快捷键/按钮打开搜索面板时聚焦输入框 */
7358
7447
  useEffect(() => {
7359
7448
  if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
@@ -7364,12 +7453,28 @@ G.SearchPanel = function SearchPanel(props) {
7364
7453
  if (props.active === true) focusInput()
7365
7454
  }, [props.active, focusInput])
7366
7455
 
7456
+ const matchKey = useCallback((path, match) => `${path}:${match.line}:${match.column}`, [])
7457
+
7458
+ /* 过滤掉用户手动「忽略」的匹配,并重新汇总数量 */
7459
+ const view = useMemo(() => {
7460
+ if (result === null) return null
7461
+ const files = []
7462
+ let total = 0
7463
+ for (const file of result.files) {
7464
+ const matches = file.matches.filter((match) => !ignored.has(matchKey(file.path, match)))
7465
+ if (matches.length === 0) continue
7466
+ files.push({ path: file.path, matches })
7467
+ total += matches.length
7468
+ }
7469
+ return { ...result, files, total }
7470
+ }, [result, ignored, matchKey])
7471
+
7367
7472
  const summary = (() => {
7368
7473
  if (status === 'loading') return t('search.searching')
7369
- if (status === 'error' || result === null) return ''
7370
- if (result.total === 0) return result.truncated === true ? t('search.truncated') : t('search.noResult')
7371
- const base = t('search.summary', { count: result.total, files: result.files.length })
7372
- return result.truncated === true ? `${base} · ${t('search.truncated')}` : base
7474
+ if (status === 'error' || view === null) return ''
7475
+ if (view.total === 0) return view.truncated === true ? t('search.truncated') : t('search.noResult')
7476
+ const base = t('search.summary', { count: view.total, files: view.files.length })
7477
+ return view.truncated === true ? `${base} · ${t('search.truncated')}` : base
7373
7478
  })()
7374
7479
 
7375
7480
  const highlight = (match) => {
@@ -7385,6 +7490,85 @@ G.SearchPanel = function SearchPanel(props) {
7385
7490
  ]
7386
7491
  }
7387
7492
 
7493
+ const applyReplace = useCallback(async (payload) => {
7494
+ if (typeof root !== 'string' || root === '' || replacing) return
7495
+ setReplacing(true)
7496
+ setReplaceError('')
7497
+ setNotice('')
7498
+ try {
7499
+ await props.onBeforeReplace?.()
7500
+ const value = await G.api('fs.replace', payload)
7501
+ if (value?.stale === true) {
7502
+ setReplaceError(t('search.stale'))
7503
+ setIgnored(new Set())
7504
+ await runSearch(query)
7505
+ return
7506
+ }
7507
+ const count = Number(value?.replacedCount) || 0
7508
+ const files = Array.isArray(value?.replacedFiles) ? value.replacedFiles : []
7509
+ setNotice(t('search.replaced', { count, files: files.length }))
7510
+ await props.onFilesChanged?.(files)
7511
+ setIgnored(new Set())
7512
+ await runSearch(query)
7513
+ } catch (err) {
7514
+ setReplaceError(G.errorText(err))
7515
+ } finally {
7516
+ setReplacing(false)
7517
+ }
7518
+ }, [root, replacing, props.onBeforeReplace, props.onFilesChanged, t, runSearch, query])
7519
+
7520
+ const requestReplaceAll = () => {
7521
+ if (view === null || view.total === 0 || replacing) return
7522
+ setReplaceError('')
7523
+ setNotice('')
7524
+ setConfirming({ count: view.total, files: view.files.length })
7525
+ }
7526
+ const doReplaceAll = () => {
7527
+ const pending = confirming
7528
+ setConfirming(null)
7529
+ if (pending === null) return
7530
+ void applyReplace({
7531
+ root,
7532
+ query: query.trim(),
7533
+ replacement,
7534
+ options: { caseSensitive, regex, preserveCase, include: includeText, exclude: excludeText },
7535
+ })
7536
+ }
7537
+ const replaceFile = (file) => {
7538
+ if (replacing) return
7539
+ void applyReplace({
7540
+ root,
7541
+ query: query.trim(),
7542
+ replacement,
7543
+ options: { caseSensitive, regex, preserveCase },
7544
+ paths: [file.path],
7545
+ })
7546
+ }
7547
+ const replaceOne = (path, match) => {
7548
+ if (replacing) return
7549
+ void applyReplace({
7550
+ root,
7551
+ query: query.trim(),
7552
+ replacement,
7553
+ options: { caseSensitive, regex, preserveCase },
7554
+ target: { path, line: match.line, column: match.column },
7555
+ })
7556
+ }
7557
+ const dismiss = (path, match) => {
7558
+ setIgnored((current) => {
7559
+ const next = new Set(current)
7560
+ next.add(matchKey(path, match))
7561
+ return next
7562
+ })
7563
+ }
7564
+ const openFirst = () => {
7565
+ const file = view?.files?.[0]
7566
+ const match = file?.matches?.[0]
7567
+ if (file !== undefined && file !== null && match !== undefined && match !== null) {
7568
+ props.onOpenFile?.(file.path, match.line, match.column)
7569
+ }
7570
+ }
7571
+
7388
7572
  const body = (() => {
7389
7573
  if (typeof root !== 'string' || root === '') {
7390
7574
  return h('div', { className: 'gufa-hint', style: { padding: '10px 12px' } }, t('explorer.openProjectFirst'))
@@ -7394,45 +7578,107 @@ G.SearchPanel = function SearchPanel(props) {
7394
7578
  }
7395
7579
  if (status === 'idle') return h('div', { className: 'gufa-hint', style: { padding: '10px 12px' } }, t('search.idle'))
7396
7580
  if (status === 'loading') return h('div', { className: 'gufa-hint', style: { padding: '10px 12px', display: 'flex', gap: 8, alignItems: 'center' } }, h(G.Spinner), t('search.searching'))
7397
- if (result === null || result.total === 0) {
7398
- const emptyText = result !== null && result.truncated === true ? t('search.truncated') : t('search.noResult')
7581
+ if (view === null || view.total === 0) {
7582
+ const emptyText = view !== null && view.truncated === true ? t('search.truncated') : t('search.noResult')
7399
7583
  return h('div', { className: 'gufa-hint', style: { padding: '10px 12px' } }, emptyText)
7400
7584
  }
7401
7585
  return h(
7402
7586
  'div',
7403
7587
  { className: 'gufa-search-results' },
7404
- ...result.files.map((file) => {
7588
+ ...view.files.map((file) => {
7405
7589
  const isCollapsed = collapsed[file.path] === true
7406
7590
  return h(
7407
7591
  'div',
7408
7592
  { key: file.path, className: 'gufa-search-file' },
7409
7593
  h(
7410
- 'button',
7594
+ 'div',
7411
7595
  {
7412
- type: 'button',
7413
7596
  className: 'gufa-search-file-head',
7597
+ role: 'button',
7598
+ tabIndex: 0,
7414
7599
  title: file.path,
7415
7600
  onClick: () => setCollapsed((current) => ({ ...current, [file.path]: !isCollapsed })),
7601
+ onKeyDown: (event) => {
7602
+ if (event.key !== 'Enter' && event.key !== ' ') return
7603
+ event.preventDefault()
7604
+ setCollapsed((current) => ({ ...current, [file.path]: !isCollapsed }))
7605
+ },
7416
7606
  },
7417
7607
  h(G.Icon, { name: isCollapsed ? 'chevron-right' : 'chevron-down', size: 11 }),
7418
7608
  h('span', { className: 'gufa-search-file-name' }, G.basename(file.path)),
7419
7609
  h('span', { className: 'gufa-search-file-dir' }, G.dirname(file.path)),
7420
7610
  h('span', { className: 'gufa-search-file-count' }, String(file.matches.length)),
7611
+ replaceOpen
7612
+ ? h(
7613
+ 'span',
7614
+ {
7615
+ className: 'gufa-search-file-replace',
7616
+ title: t('search.replaceThisFile'),
7617
+ role: 'button',
7618
+ onClick: (event) => {
7619
+ event.stopPropagation()
7620
+ event.preventDefault()
7621
+ replaceFile(file)
7622
+ },
7623
+ },
7624
+ h(G.Icon, { name: 'pencil', size: 11 }),
7625
+ )
7626
+ : null,
7421
7627
  ),
7422
7628
  isCollapsed
7423
7629
  ? null
7424
7630
  : file.matches.map((match, index) =>
7425
7631
  h(
7426
- 'button',
7632
+ 'div',
7427
7633
  {
7428
7634
  key: `${file.path}:${match.line}:${match.column}:${index}`,
7429
- type: 'button',
7430
7635
  className: 'gufa-search-match',
7636
+ role: 'button',
7637
+ tabIndex: 0,
7431
7638
  title: `${file.path}:${match.line}:${match.column}`,
7432
7639
  onClick: () => props.onOpenFile?.(file.path, match.line, match.column),
7640
+ onKeyDown: (event) => {
7641
+ if (event.key !== 'Enter') return
7642
+ event.preventDefault()
7643
+ props.onOpenFile?.(file.path, match.line, match.column)
7644
+ },
7433
7645
  },
7434
7646
  h('span', { className: 'gufa-search-line' }, String(match.line)),
7435
7647
  h('span', { className: 'gufa-search-text' }, ...highlight(match)),
7648
+ h(
7649
+ 'span',
7650
+ { className: 'gufa-search-match-actions' },
7651
+ replaceOpen
7652
+ ? h(
7653
+ 'span',
7654
+ {
7655
+ className: 'gufa-search-row-action',
7656
+ title: t('search.replaceOne'),
7657
+ role: 'button',
7658
+ onClick: (event) => {
7659
+ event.stopPropagation()
7660
+ event.preventDefault()
7661
+ replaceOne(file.path, match)
7662
+ },
7663
+ },
7664
+ h(G.Icon, { name: 'pencil', size: 11 }),
7665
+ )
7666
+ : null,
7667
+ h(
7668
+ 'span',
7669
+ {
7670
+ className: 'gufa-search-row-action',
7671
+ title: t('search.dismiss'),
7672
+ role: 'button',
7673
+ onClick: (event) => {
7674
+ event.stopPropagation()
7675
+ event.preventDefault()
7676
+ dismiss(file.path, match)
7677
+ },
7678
+ },
7679
+ h(G.Icon, { name: 'close', size: 11 }),
7680
+ ),
7681
+ ),
7436
7682
  ),
7437
7683
  ),
7438
7684
  )
@@ -7473,6 +7719,7 @@ G.SearchPanel = function SearchPanel(props) {
7473
7719
  query === ''
7474
7720
  ? null
7475
7721
  : h(G.IconButton, { title: t('search.clear'), onClick: () => { setQuery(''); focusInput() } }, h(G.Icon, { name: 'close', size: 11 })),
7722
+ h(G.IconButton, { title: t('search.replaceToggle'), onClick: () => setReplaceOpen((value) => !value) }, h(G.Icon, { name: replaceOpen ? 'chevron-up' : 'chevron-down', size: 12 })),
7476
7723
  ),
7477
7724
  h(
7478
7725
  'div',
@@ -7491,8 +7738,102 @@ G.SearchPanel = function SearchPanel(props) {
7491
7738
  title: t('search.regex'),
7492
7739
  onClick: () => setRegex((value) => !value),
7493
7740
  }, '.*'),
7741
+ ),
7742
+ replaceOpen
7743
+ ? h(
7744
+ React.Fragment,
7745
+ null,
7746
+ h(
7747
+ 'div',
7748
+ { className: 'gufa-search-input-wrap gufa-search-replace-row' },
7749
+ h(G.Icon, { name: 'pencil', size: 12 }),
7750
+ h('input', {
7751
+ className: 'gufa-search-input',
7752
+ type: 'text',
7753
+ value: replacement,
7754
+ placeholder: t('search.replacePlaceholder'),
7755
+ spellCheck: false,
7756
+ onChange: (event) => setReplacement(event.target.value),
7757
+ onKeyDown: (event) => {
7758
+ if (event.key !== 'Enter') return
7759
+ event.preventDefault()
7760
+ requestReplaceAll()
7761
+ },
7762
+ }),
7763
+ h('button', {
7764
+ type: 'button',
7765
+ className: 'gufa-search-toggle',
7766
+ 'data-active': preserveCase ? '' : undefined,
7767
+ title: t('search.preserveCase'),
7768
+ onClick: () => setPreserveCase((value) => !value),
7769
+ }, 'AB'),
7770
+ ),
7771
+ h(
7772
+ 'div',
7773
+ { className: 'gufa-search-actions' },
7774
+ h(
7775
+ 'button',
7776
+ {
7777
+ type: 'button',
7778
+ className: 'gufa-search-action',
7779
+ 'data-primary': '',
7780
+ disabled: replacing || view === null || view.total === 0,
7781
+ onClick: requestReplaceAll,
7782
+ },
7783
+ replacing ? t('search.replacing') : t('search.replaceAll'),
7784
+ ),
7785
+ ),
7786
+ )
7787
+ : null,
7788
+ h(
7789
+ 'label',
7790
+ { className: 'gufa-search-filter' },
7791
+ h('span', { className: 'gufa-search-filter-label' }, t('search.include')),
7792
+ h('input', {
7793
+ className: 'gufa-search-filter-input',
7794
+ type: 'text',
7795
+ value: includeText,
7796
+ placeholder: t('search.includePlaceholder'),
7797
+ spellCheck: false,
7798
+ onChange: (event) => setIncludeText(event.target.value),
7799
+ }),
7800
+ ),
7801
+ h(
7802
+ 'label',
7803
+ { className: 'gufa-search-filter' },
7804
+ h('span', { className: 'gufa-search-filter-label' }, t('search.exclude')),
7805
+ h('input', {
7806
+ className: 'gufa-search-filter-input',
7807
+ type: 'text',
7808
+ value: excludeText,
7809
+ placeholder: t('search.excludePlaceholder'),
7810
+ spellCheck: false,
7811
+ onChange: (event) => setExcludeText(event.target.value),
7812
+ }),
7813
+ ),
7814
+ h(
7815
+ 'div',
7816
+ { className: 'gufa-search-summarybar' },
7494
7817
  h('span', { className: 'gufa-search-summary', title: summary }, summary),
7818
+ view !== null && view.total > 0
7819
+ ? h('button', { type: 'button', className: 'gufa-search-link', onClick: openFirst }, t('search.openInEditor'))
7820
+ : null,
7495
7821
  ),
7822
+ confirming !== null
7823
+ ? h(
7824
+ 'div',
7825
+ { className: 'gufa-search-confirm' },
7826
+ h('div', null, t('search.confirmReplace', { count: confirming.count, files: confirming.files })),
7827
+ h(
7828
+ 'div',
7829
+ { className: 'gufa-search-confirm-actions' },
7830
+ h('button', { type: 'button', className: 'gufa-search-action', onClick: () => setConfirming(null) }, t('search.confirmNo')),
7831
+ h('button', { type: 'button', className: 'gufa-search-action', 'data-primary': '', onClick: doReplaceAll }, t('search.confirmYes')),
7832
+ ),
7833
+ )
7834
+ : null,
7835
+ notice !== '' ? h('div', { className: 'gufa-search-notice' }, notice) : null,
7836
+ replaceError !== '' ? h('div', { className: 'gufa-search-error' }, `${t('search.replaceError')}:${replaceError}`) : null,
7496
7837
  ),
7497
7838
  h('div', { className: 'gufa-panel-body gufa-scroll' }, body),
7498
7839
  )
@@ -10609,6 +10950,49 @@ G.GufaApp = function GufaApp(props) {
10609
10950
  }
10610
10951
  }, [project, patchTab, refreshGit, t])
10611
10952
 
10953
+ /* 搜索面板批量替换前:先把所有未落盘的编辑器缓冲保存掉,避免磁盘旧内容覆盖用户输入 */
10954
+ const beforeSearchReplace = useCallback(async () => {
10955
+ flushBuffersRef.current?.()
10956
+ const pending = new Set(editorBuffersRef.current.keys())
10957
+ for (const tab of tabsRef.current ?? []) {
10958
+ if (tab !== null && tab !== undefined && tab.dirty === true) pending.add(tab.path)
10959
+ }
10960
+ for (const path of pending) {
10961
+ try {
10962
+ await saveFile(path)
10963
+ } catch {
10964
+ /* 单个保存失败不阻断替换 */
10965
+ }
10966
+ }
10967
+ }, [saveFile])
10968
+
10969
+ /* 搜索面板替换完成后:刷新目录/Git,并把已打开标签同步成磁盘最新内容 */
10970
+ const onSearchFilesChanged = useCallback(async (paths) => {
10971
+ if (project !== null && Array.isArray(paths) && paths.length > 0) {
10972
+ for (const path of paths.slice(0, 30)) {
10973
+ const tab = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
10974
+ if (tab === undefined) continue
10975
+ try {
10976
+ const doc = await G.api('fs.read', { root: project.root, path })
10977
+ editorBuffersRef.current.delete(path)
10978
+ patchTab(path, {
10979
+ content: doc.content,
10980
+ revision: doc.revision,
10981
+ savedRevision: doc.revision,
10982
+ savedContent: doc.content,
10983
+ dirty: false,
10984
+ size: doc.size,
10985
+ })
10986
+ } catch {
10987
+ /* 文件已被删除:忽略 */
10988
+ }
10989
+ }
10990
+ }
10991
+ setRefreshToken((token) => token + 1)
10992
+ setGitRefreshToken((token) => token + 1)
10993
+ void refreshGit()
10994
+ }, [project, patchTab, refreshGit])
10995
+
10612
10996
  /** 顶栏提示:错误常驻红色;成功用绿色 toast,1.2 秒后自动消失。 */
10613
10997
  const successTimerRef = useRef(null)
10614
10998
  const showBanner = useCallback((text, tone) => {
@@ -12136,6 +12520,8 @@ G.GufaApp = function GufaApp(props) {
12136
12520
  root: project?.root ?? null,
12137
12521
  active: ui.view === 'search',
12138
12522
  onOpenFile: (path, line, column) => void openFileAt(path, line, column),
12523
+ onBeforeReplace: beforeSearchReplace,
12524
+ onFilesChanged: onSearchFilesChanged,
12139
12525
  })),
12140
12526
  h('div', { key: 'git', style: { display: ui.view === 'git' ? 'flex' : 'none', flex: '1 1 auto', minHeight: 0, flexDirection: 'column' } },
12141
12527
  h(G.GitPanel, {
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.62</string>
11
- <key>CFBundleVersion</key><string>1.3.62</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.64</string>
11
+ <key>CFBundleVersion</key><string>1.3.64</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -157,7 +157,14 @@ AI 是通过 Host 工具直接写盘,客户端收不到任何通知。
157
157
  - 结果行带 `line/column/start/end/text`,前端高亮 `start..end`;点击结果通过 `G.bus 'editor:reveal'` 让 Monaco 跳到对应行列(tab 切换未完成时事件先存到 `pendingRevealRef`)。
158
158
  - **坑**:往 `G.CSS` 模板里加规则时一定插在完整规则之后。曾把搜索样式插进 `.gufa-explorer-notice{...}` 规则中间,CSS nesting 把整块样式变成后代选择器,面板渲染成原生输入框。插入后检查 `client.js` 里 `.gufa-explorer-notice{...}` 的闭合括号是否在搜索块之前。
159
159
 
160
- ## 5.1 摸鱼会话框比编辑器黑:官方会话根节点自己又画了一层底
160
+ ## 全局替换(1.3.63 新增)
161
+
162
+ - Host 侧 `fs.replace`:与 `fs.search` 共用 `listProjectCandidates`(Git 项目 `git ls-files`,非 Git BFS 遍历);按 query 构造正则(字面量走 `escapeRegExp` + 函数 replacer 保持 `$` 字面量,正则模式支持 `$1` 分组),只写内容确实变化的文件。
163
+ - 正则模式禁止「能匹配空字符串」的表达式(如 `a*`),否则会在每个字符间插入替换文本。
164
+ - 替换前客户端先 `beforeSearchReplace`:flush 编辑器缓冲 + 保存所有脏标签,避免磁盘旧内容覆盖用户输入;替换后 `onSearchFilesChanged` 重新读盘并 patch 已打开标签、刷新目录/Git。
165
+ - 前端替换入口在搜索输入框右侧 chevron:展开后出现替换输入、`全部替换`、每个文件头部的单文件替换铅笔按钮;全部替换需要一次内联确认(直接写盘,编辑器撤销无效)。
166
+
167
+ ## 5.1 摸鱼会话框比编辑器黑:官方会话根节点又自己画了一层底
161
168
 
162
169
  - 现象:摸鱼里编辑器/终端都统一了,右侧会话框看起来明显更黑更实。
163
170
  - 实测(同屏同底层对比法):编辑器有效 alpha=0.570,会话框=0.878 → 会话框多叠了一层 ~0.72 的暗底。