Skip to content

feat(macos): add editor find options and replace-in-file - #346

Merged
1lck merged 3 commits into
1lck:previewfrom
Wz58luck:feat/editor-find-replace
Aug 30, 2026
Merged

feat(macos): add editor find options and replace-in-file#346
1lck merged 3 commits into
1lck:previewfrom
Wz58luck:feat/editor-find-replace

Conversation

@Wz58luck

@Wz58luckWz58luck commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

背景

Closes#327。为编辑器内查找补全匹配选项与替换能力,与项目级搜索的体验保持一致。

变更

  • 新增 FindInFileOptions / FindInFileMatcher(纯 Foundation 值类型):Match Case、Whole Words(标准词边界:字母/数字/下划线,串首串尾视为边界)、Regular Expression(NSRegularExpression;与 Whole Words 同开时模式外包 \b(?:…)\b);零宽度匹配跳过;非法正则只呈现错误态不抛错;字面量替换原样使用,正则替换支持 $n 捕获组模板。
  • FindBarView 纵向扩展:选项菜单(任一开启时着色)、可展开替换行(Replace / Replace All,无匹配时禁用)、非法正则时查找图标显示错误色;替换行展开后焦点移到替换输入框。
  • 替换管线:Replace Next 走 insertText(_:replacementRange:) 标准输入管线(撤销、委托回调与手工编辑一致),替换后自动跳到下一处并跳过替换文本新产生的匹配;Replace All 通过 shouldChangeText + NSTextStorage 批量替换 + didChangeText 一次提交,形成单个撤销步骤,之后整篇重算匹配。
  • replace-in-file 命令注册进 LitheCommandCatalog(默认 Cmd+R)、LitheActionRegistrycanPerformShortcutCommand 与 Navigate 菜单,可在 Keymap 中自定义;Cmd+F 行为保持现状,Cmd+R 在查找/替换行之间切换;Esc 关闭行为不变。
  • 按行增量重算窗口向两侧各扩一个字符,保证行边界处全词匹配的边界字符正确参与判定。
  • AppModel 的文件内查找门面抽取为 AppModel+FindInFile.swift(满足 1800 行上限)。

测试

  • 新增 FindInFileMatcherTests(13 项:大小写/音调不敏感回归、Match Case、全词边界、正则捕获组展开、非法模式、零宽度跳过、子范围枚举等);扩展 EditorChromeModelTestsKeyboardShortcutTests 命令数 31→32;LitheCoreLogicTests 查找调用点同步新签名。
  • ./scripts/test-macos.sh:677 tests / 79 suites 全部通过。
  • verify-test-stability.shtest-stability-macos.sh -- --filter FindInFileMatcherverify-service-boundaries.sh 全部通过。

变更后:
image

@Wz58luck
Wz58luck requested a review from 1lck as a code ownerAugust 30, 2026 03:30
Comment threadmacos/Sources/Lithe/Models/Editor/FindInFileMatcher.swift Outdated
Comment threadmacos/Sources/Lithe/Views/Editor/CodeEditorView.swift
@Wz58luck

Copy link
Copy Markdown
ContributorAuthor

已fix

- Add FindInFileOptions/FindInFileMatcher with Match Case, Whole Words,
and Regular Expression matching aligned with project search semantics
- Extend FindBarView with an options menu, expandable replace row
(Replace / Replace All), and invalid-regex error state
- Replace-next routes through insertText for standard undo; replace-all
commits via shouldChangeText + textStorage as a single undo step
- Register replace-in-file (Cmd+R) in the command catalog, action
registry, Navigate menu, Keymap settings, and zh-Hans localization
Closes1lck#327
- Unify replacement template docs and comments on $n numeric capture
groups; ${name} named-group templates are not expanded by the current
SDK and return verbatim
- Bind replace notifications to the active document: notifications now
carry documentID and CodeTextView ignores mismatched targets so split
editors never replace the wrong file
- Recompute matches across the whole document for regex queries where
matches can span lines; keep the line-window incremental path for
single-line literal queries
- Add regression tests for cross-line regex matches and notification
document gating
@1lck
1lck merged commit 3fa2f7e into 1lck:previewAug 30, 2026
9 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Wz58luck@1lck