Offer the rendered diff in the editor context menu for committed diffs - #62
Conversation
After phine-apps#60 the title-bar button renders a committed revision diff, but right-clicking inside that diff editor still did not offer "Show Rich Markdown Diff" — the button uses the built-in `isInDiffEditor` context, while the context menu is gated on `rich-markdown-diff.canShowRenderedDiff`, and the two disagreed. The context key is computed by `updateRenderedDiffContext`, which — like the original phine-apps#59 bug — rebuilds the active editor's `git:` URI as a plain `file:` URI, dropping the commit ref. The comparison then resolves as HEAD-vs-working-tree, a committed blob is not dirty, and `isActionableSingleFileComparison` returns false, so the key stayed off. - Add `getActiveRevisionComparison`, reusing phine-apps#60's `getActiveDiffTabUriPair` and `getRevisionComparison`, to report the revision diff the active tab is showing. - In `updateRenderedDiffContext`, short-circuit to canShow = true when the active tab is a markdown revision diff, before the ref-dropping fallback runs. The markdown-path check stops a non-markdown diff in another editor group from enabling the key. - Factor the repeated "set the context key only if it changed, and only if this update has not been superseded" logic into `setCanShowRenderedDiff`, and use it at the existing call sites. Fixes phine-apps#61 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Verified live in VS Code 1.130.0 (Windows) with a local build of this branch: on a committed For reference, one thing that is intentionally not addressed here: the inline hover icon on a file row still can't appear under a commit in the Graph. VS Code exposes no per-change menu hook there — the finest history/graph contribution point is |
Fixes #61. Follow-up to #60.
After #60, the title-bar button renders a committed revision diff, but right-clicking inside that diff editor still does not offer Show Rich Markdown Diff. The button's
whenuses the built-inisInDiffEditorcontext; the editor context menu is gated onrich-markdown-diff.canShowRenderedDiff. The two disagreed.Why the context key stayed off
updateRenderedDiffContextcomputes the key. When a committed diff is focused, the active editor is the modified side — agit:URI carrying the commit ref. Lines 557–562 rebuild it as a plainfile:URI, dropping the ref (the same root cause as #59). The comparison then resolves as HEAD-vs-working-tree; a committed blob isn't dirty;isActionableSingleFileComparisonreturns false → key stays off → menu item hidden.What changed
getActiveRevisionComparison(commandTarget.ts) reuses Render diffs for committed changes, not just uncommitted ones #60'sgetActiveDiffTabUriPairandgetRevisionComparisonto report the revision diff the active tab is showing.updateRenderedDiffContextshort-circuits tocanShow = truewhen the active tab is a markdown revision diff, before the ref-dropping fallback runs. TheisMarkdownPath(toFileBackedUri(...))check keeps a non-markdown revision diff in another editor group from enabling the key (reachable via the existingupdateRenderedDiffContext(mdEditor)recursion, where the passed editor and the active tab can differ).setCanShowRenderedDifffactors out the "set the key only if the value changed and this update hasn't been superseded by a newer generation" logic that was duplicated at two call sites, and is used at the new site too.No
package.jsonwhenclauses change: the menu already requires(editorLangId == markdown || resourceLangId == markdown) && rich-markdown-diff.canShowRenderedDiff. Only the context key's value is corrected.Scope is deliberately narrow — the key flips to
trueonly for a markdown diff whose active tab names a commit, tag, or branch ref. HEAD-vs-working-tree and staged diffs still resolve through the unchanged path (getRevisionComparisonreturns undefined forHEAD,"", and~), so no existing behavior moves.Tests
3 new integration tests in
commandTarget.test.ts(50 → written before the code): a commit-to-commit diff tab is detected, while a HEAD-to-working-tree tab and a plain markdown editor are not.test:unitstays at 150.pnpm run pretestis clean.The context-key side effect isn't observable through the public API, so — as in #60 — I proved the wiring end-to-end with a temporary harness against a real two-commit git repository: opening the committed diff and driving the context update flipped the module's
lastCanShowRenderedDifftotrue. With only the new short-circuit disabled (helper and tests left in place), the same harness reportedfalse, reproducing #61 exactly. The harness is not included in the PR.Note
Verified programmatically that the context key now flips to
truefor a committed markdown diff (above). The menu'swhenclause is that key plus the markdown language gate, both satisfied, so the right-click item should now appear; a maintainer running a build can confirm the live menu.