Repository navigation
fix(editor): keep ShowContent from reporting edits back to the host (#2377) - #2399
Merged
Merged
Conversation
…the OnEdit exception (#2377) - replaceContent took recordUndo and report, which always moved together; one fromDisk flag leaves no meaningless combination. - Config.OnEdit said it reports every replacement; it now names the ShowContent exception. - placeCompletionCaret replaced an LSP-synced document's text with ShowContent, which no longer tells the language server; it now uses Reload, as a changed file on disk does. - The Agent Note records why the plugin preview path loses nothing, and the matrix text no longer names the internal signature.
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.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
在 Git 工作区打开未跟踪文本文件的 Diff 页签时,即使用户没有任何输入,文件也会在自动保存后每隔一轮在末尾追加一个换行符(LF 文件追加 LF,CRLF 文件追加 CRLF),不断污染工作区并可能触发写入占用错误。
原因是
editorview.View.ShowContent内部复用了replaceFromDisk,在宿主将文档内容同步给只读或从属视图展示时,仍计算差异并通过OnEdit上报。diffSideEditor首次以不含末尾换行的pane.text初始化右侧视图后,无标签文档加载完成并调用ShowContent(doc.view.CopyContent()),上报出的尾部换行差异被diffEdited再次ApplyEdit回无标签文档,触发自动保存 ->reloadDiffsOfPath->ShowContent死循环。改动 / Changes
desktop/internal/editorview/view.go:将replaceFromDisk的主体抽出为replaceContent(content Content, fromDisk bool);“保留撤销”和“上报OnEdit”总是同时成立或同时不成立,所以只用一个参数。Reload和ResolveWithDisk经replaceFromDisk传fromDisk=true,行为不变。Config.OnEdit的注释原来写“报告每一次替换”,现在写明ShowContent是例外。desktop/internal/editorview/diffdecor.go:ShowContent改为调用v.replaceContent(content, false)并更新注释说明——替换宿主展示内容时不保留撤销/重做历史,也不向OnEdit上报编辑(同时省去窗口线程上的rope.Diff和临时撤销快照)。desktop/internal/workbench/source_preview.go:移除previewEdited中因ShowContent不再触发OnEdit而变成冗余的p.diffs.mirroring++/--护栏(保留mirrorPreviewEdit中ApplyEdit路径的mirroring计数)。desktop/internal/editorview/diffdecor_test.go:新增TestShowContentDoesNotReportEditOrMirrorBack,验证ShowContent在多轮同步中不上报OnEdit、不清空/改写来源文档且不产生撤销历史。desktop/internal/workbench/difftab_test.go:新增TestDiffTabUntrackedFileDoesNotEditOrAutosaveOnOpenAndReload,验证未跟踪 LF / CRLF 文件打开工作区 Diff、无标签文档加载、多轮reloadDiffsOfPath与关闭页签过程中文档保持干净、不调度自动保存且磁盘字节不变。desktop/internal/workbench/pluginsemantics_test.go:测试助手placeCompletionCaret原来用ShowContent给已同步语言服务器的文档换上磁盘新内容。改动后ShowContent不再通知语言服务器,测试里的文档和语言服务器副本会不一致,所以改用Reload(与“磁盘文件变化”的真实路径一致,也恢复了这个助手在本 PR 之前的同步行为)。shared/platform-feature-matrix/features/git-diff-review.json:补充#2377验证说明与备注(保持pending,待 Windows 实机验收)。.agents/notes/implemented/bug-fix/2026-11-24-diff-show-content-edit-loop.md:记录ShowContent不上报OnEdit的行为约束与备选方案取舍。不在本 PR 范围内 / Out of scope
类型专属:fix
复现与根因
\n/\r\n的未跟踪文件并打开工作区 Diff。TestShowContentDoesNotReportEditOrMirrorBack报出ShowContent reported [{StartLine:1 StartColumn:3 EndLine:1 EndColumn:3 Text:\n}];TestDiffTabUntrackedFileDoesNotEditOrAutosaveOnOpenAndReload在首轮即失败,提示untracked_lf.txt round 0: document became dirty with "alpha\nbeta\n\n"。ShowContent不向OnEdit上报编辑,文档保持 clean、不调度自动保存、磁盘文件字节不变。git log -S或git blame查):Viva 迁移提交0faecba49(PR Epic(0.7.0): 基于 Viva 框架的跨平台方案的迁移(#1794) #1799)引入ShowContent时复用replaceFromDisk并仅在事后清空undo/redo,未关闭reportEdit;而difftab.go中的diffSideEditor未像后来 feat(desktop): 问题预览按严重程度着色并可直接编辑,选中色加深 #2110 的source_preview.go那样包裹mirroring屏蔽。editorview和workbench)。检查项
desktop/internal/editorview/diffdecor_test.go(TestShowContentDoesNotReportEditOrMirrorBack,修复前第 1 轮报出尾部\n编辑)与desktop/internal/workbench/difftab_test.go(TestDiffTabUntrackedFileDoesNotEditOrAutosaveOnOpenAndReload,修复前首轮文档即变为 dirty"alpha\nbeta\n\n")。ShowContent全部 4 处生产调用点(difftab.go:629、source_preview.go:288、source_preview.go:302、plugin_workflow.go:239)与replaceFromDisk全部调用点(Reload、ResolveWithDisk、ShowContent)。其中plugin_workflow.go:239是唯一对主文档调用ShowContent的生产路径(刷新已打开的lithe-plugin-preview://虚拟文档):它以前经OnEdit进入documentEdited/mirrorDocumentEdit,但这些副作用对虚拟文档本来就全部跳过(自动保存、恢复草稿、最近文件、编辑器动作按virtual提前返回;languageID为空,找不到语言服务器;没有 Diff 页签或问题预览显示这类路径)。Markdown/HTML 预览按Revision()刷新,replaceContent仍递增版本号,所以预览照常更新。source_preview.go中因本次改动变成冗余的ShowContentmirroring护栏已按第九节规则在本次一并删除)。.agents/notes/implemented/bug-fix/记录:.agents/notes/implemented/bug-fix/2026-11-24-diff-show-content-edit-loop.md。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:shared/platform-feature-matrix/features/git-diff-review.json补充了#2377验证依据与备注,verificationStatus保持pending。./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD。.artifacts/下生成的矩阵视图。git-diff-review.json。插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空。shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 Skill。UI 验证 / UI evidence
N/A:本次修复不涉及布局、控件、样式、文案、菜单、弹窗或可见交互状态变更,仅修复
ShowContent不再误报OnEdit。统一日志系统 / Structured logging
N/A:未新增或改动日志事件、写入器、界面警告/错误或丢弃错误的处理边界。
界面文案 / i18n
N/A:未新增或修改任何用户可见文案。
逻辑归属 / Logic placement
editorview.View.ShowContent是否触发视图OnEdit回调及视图层mirroring护栏),不涉及可共享业务规则或原生 I/O 规则变更。性能与内存 / Performance and memory
ShowContent不再在窗口线程上调用diskEdit(rope.Diff)和分配撤销快照。desktop/internal/editorview/**),已在同一台空闲 Apple M4 机器上以--count 6运行改动前后性能基线:./scripts/desktop/perf/editor-bench.sh run --count 6 --out .artifacts/editor-perf/before.txt与--out .artifacts/editor-perf/after.txt --base .artifacts/editor-perf/before.txt,并用compare对比。editorview基准均为✅ within(无任何新增超预算项);3 项既有超预算项(BenchmarkEditorSyntaxFullPass/go|java|markdown/100KiB)为改动前已存在的语法全量扫描耗时项。perfhistory compare提示 1 项统计波动(BenchmarkEditorViewPaste/go/10MiB: 样本最大值 2093 allocs/op vs 原 2092,而均值由 2090 降至 2086,与ShowContent无关)。设置 / Settings
N/A:未新增或修改任何设置项或设置页面。
插件契约 / Plugin contract
N/A:未修改 Rust Core 插件契约、能力版本、插件函数协议或宿主方法/通知。
发行包与资源 / Bundle and resources
N/A:未新增或修改任何运行时资源、缓存路径或打包步骤。
无用代码与重构 / Dead code and refactoring
desktop/internal/workbench/source_preview.go中包裹view.ShowContent的冗余p.diffs.mirroring++/--。refactor标签的 Issue:本次未在改动范围内发现需建单的既有债务。验证 / Verification
./scripts/desktop/desktop-go.sh test -count=1 ./internal/editorview/./scripts/desktop/desktop-go.sh test -count=1 ./internal/workbench/ -run 'TestDiff|TestProblems|TestSourcePreview'./scripts/desktop/desktop-go.sh test -race ./internal/editorview/./scripts/desktop/desktop-go.sh test -race ./internal/workbench/ -run 'TestDiff|TestDocument'./scripts/desktop/desktop-go.sh test ./...internal/workbench(363.244s)等全部业务包通过;并发负载下internal/localshell(TestClosingAnIntegratedShellRightAfterACommandHangsUpItsJobs/zsh)超时 1 次,单独重跑./scripts/desktop/desktop-go.sh test -count=1 ./internal/localshell/通过(8.474s)./scripts/desktop/perf/editor-bench.sh run --count 6(改动前后对比)editorview基准✅ within,无新增超预算项./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh&--base origin/main./.agents/skills/write-stable-tests/scripts/test-stability-macos.sh(两条新增回归用例).artifacts/test-stability/index.html./scripts/agent-notes/verify-agent-notes.sh./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh&verify-platform-feature-matrix-change.sh origin/main HEADrg命令 &gofmt -lview.go/diffdecor.go到origin/main后运行两条新回归测试round 1: ShowContent reported …Text:\n;untracked_lf.txt round 0: document became dirty with "alpha\nbeta\n\n"),恢复修复后通过./scripts/desktop/desktop-go.sh test -count=1 ./internal/editorview/./scripts/desktop/desktop-go.sh test -count=3 ./internal/workbench/ -run 'TestLSPSignatureHelpStaysClearOfCaretWhenCompletionIsAbove|TestCompletionPopup|TestDiffTabUntrackedFileDoesNotEdit'-tags 'vivahead lithevisual'运行TestVisualCompletionPopup(使用placeCompletionCaret)./scripts/desktop/desktop-go.sh test -count=1 ./internal/workbench/ -run 'TestDiff|TestSourcePreview|TestProblems|Preview|TestCompletion|TestLSP|TestDocument|Tabless|Semantic|TestPlugin|TestSignature'verify-agent-notes.sh、verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEAD未能执行的检查和原因:
replaceContent的两个总是相同的布尔参数合成一个,执行的分支和原提交完全相同,所以没有重跑编辑器性能基线;上面的前后对比仍然适用。pending。提交前确认 / Final checks
main创建;目标分支:main.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图