Skip to content

fix(markdown): preserve diff switching and compare selected files as text - #616

Closed
ONEGAYI wants to merge 2 commits into
cweijan:mainfrom
ONEGAYI:codex/markdown-text-compare
Closed

ONEGAYI wants to merge 2 commits into
cweijan:mainfrom
ONEGAYI:codex/markdown-text-compare

Conversation

@ONEGAYI

@ONEGAYI ONEGAYI commented Sep 17, 2026

Copy link
Copy Markdown

When a Markdown comparison uses custom editors, the pencil command can reopen only one file instead of keeping the comparison. This change preserves the original/modified pair and toggles between a native text diff and the normally associated Markdown editors where supported by VS Code.

The native diff uses the real URIs, so the modified side remains editable and saves to the original file. Dirty source tabs are retained: closing one on VS Code 1.86 can otherwise revert an unsaved buffer even while a custom comparison displays it. Clean replaced tabs are closed to avoid accumulating comparisons. Opaque custom comparisons are resolved conservatively from their labels and open documents; ambiguous pairs are rejected rather than guessed.

A new Explorer action, Compare Selected Markdown as Text, accepts two Markdown files and opens a native text diff from the first view. Normal single-file associations are unchanged. The pencil menu now covers .markdown and uppercase Markdown extensions too. English and Chinese labels and usage instructions are included.

Validation

  • npm run test:markdown: 24 tests passed on Node 20 and Node 24; no new dependency is required.
  • Real extension-host integration: 9 scenarios passed on VS Code 1.86.2 and 1.138.0, covering first-open text tabs, both focus sides, closed source tabs, missing title URI, repeated switching, unsaved drafts, saving only the modified file, single-file switching, and concurrent switching in a second editor group.
  • npm run build, changed-source ESLint and git diff --check passed.
  • Two independent review-loop rounds completed; the .markdown pencil visibility issue found during review was fixed and rechecked.

Compatibility and limits

  • Native forcing relies on the boolean override: true accepted by VS Code's vscode.diff converter, an option not present in the public typed API. Real-host regression tests document this compatibility seam.
  • Recent VS Code versions may use the native text fallback even when reopening through normal Markdown associations; this PR does not override that platform behavior.
  • Single-file switching is guarded for versions without the Tab API. The full VS Code 1.64 workbench and browser extension host were not run. Explorer command arguments and menu contributions are tested; visual right-click menu interaction remains a manual check.
  • Integration test setup is documented in test/integration/README.md.

Based directly on upstream 908258d; this branch contains only the comparison fix and the Explorer entry, without fork-only changes.

- Keep both original resources when toggling between native text diffs and
  associated Markdown editors, including opaque custom comparisons on VS Code
  1.86. Reject ambiguous file pairs instead of opening an unrelated document.
- Force the native diff through the boolean override converter option, keeping
  real editable buffers and their normal save lifecycle. Retain dirty source
  tabs because closing them can revert unsaved content on VS Code 1.86.
- Preserve single-file switching on versions without the Tab API and return
  command promises in both extension hosts.
- Add planner, compatibility and real extension-host regression tests, with
  a unit runner that also works on Node 20.
- Add an Explorer action for two selected Markdown files, validating both
  resources before opening the first view as a native text comparison.
- Add English and Chinese menu labels and expose the pencil for .markdown
  and case-insensitive Markdown extensions as well as .md.
- Document platform fallbacks and test execution; cover invalid selections,
  menu availability, first-open text tabs and concurrent switching in a second
  editor group.

Validation: 24 unit tests on Node 20 and 24; 9 extension-host scenarios each
on VS Code 1.86.2 and 1.138.0; production build and changed-source ESLint pass.
Two review-loop rounds completed with independent final review.
ONEGAYI added a commit to ONEGAYI/vscode-office that referenced this pull request Sep 17, 2026
- 合入基于上游 HEAD 的独立修复分支,对应上游 PR cweijan#616。
- 保留双向对照切换中的文件对和草稿,增加资源管理器纯文本比较入口。
- 合并态构建及单元、webview、浏览器、VS Code 1.86.2 宿主验证通过。
@ONEGAYI ONEGAYI closed this Sep 19, 2026
@ONEGAYI
ONEGAYI deleted the codex/markdown-text-compare branch September 19, 2026 02:07
Sign up for free to 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.

1 participant