Repository navigation
fix(search): 搜索后正文命中持久高亮(CM6 编辑/源码态) - #1969
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更概述
⌘F搜索浮窗输入多次出现的词后,编辑态/源码态的 CodeMirror 6 正文不再持久高亮全部命中(只剩结果行<mark>与定位选区)。根因:#981 移除 CM6 内置searchKeymap时一并去掉了搜索装饰能力,自研浮窗只向编辑器派发selection + scrollIntoView,从不派发搜索装饰(全仓无highlightMatches/SearchQuery)。关联 Issue
Closes #1841
变更内容
src/editors/searchHighlight.ts:StateEffect setSearchHighlight+StateField<DecorationSet>,按命中区间生成Decoration.mark({class:"cm-search-hit"}),越界/倒置区间防护,EditorView.decorations.from提供;随文档变更map。src/editors/setup.ts:baseEditorExtensions()装配该扩展(编辑态与源码态都生效,不进decorCompartment)。src/components/Content/SearchReplacePanel.tsx:单个useEffect把hits区间派发给本面板panelId的视图;空查询/预览态/关闭浮窗时派发清除(appliedKeyRef去抖,挂载空态不派发)。既有locate/替换逻辑不变。src/styles/search-float.css:.cm-search-hit高亮规则(token 圆角)。SearchReplacePanel.test.tsx将既有「dispatch 次数」断言改为严格语义断言(定位选区事务恰好 1 次、替换事务恰好 1 次,空态not.toHaveBeenCalled),非削弱;新增 e2esearch-body-highlight.spec.ts。范围说明
按票面「修复落点」只覆盖 CM6 正文(编辑/源码态)。阅读/预览态正文由独立
PreviewView(HTML)渲染,属规格缺口(票面明示「不在本票补规格条款,属 change 线」),未改。影响范围
baseEditorExtensions增加一个独立 StateField,与既有editors/decorations/装饰并存(各自EditorView.decorations.from)。仅搜索浮窗驱动;不改搜索定位/替换/徽标/键盘。验证方式
SearchReplacePanel.test.tsx21 通过。search-body-highlight.spec.ts2/2;既有search-float-arrowkeys.spec.ts5/5 回归通过。.cm-search-hit命中节点数 = 0(红);修复后编辑态 3 处命中全部.cm-search-hit且背景非透明(绿)、清空/关闭后归 0;源码态同样 3 处。.artifacts/1841/state-coverage.json(4 态:编辑全命中、源码全命中、清空、关闭清除)。e2e/search-float.spec.ts的「外框圆角同构」用例在基线(f00bc1d1)上即确定性失败(12px vs 8px),与本改动无关,未纳入本 PR。质量门禁引用
.cm-search-hit计数 0。.cm-search-hit数量与计算背景色,不调内部函数。风险评估
风险等级: low
来源: ai-generated
回滚方案
git revert 即可回滚