Repository navigation
Various improvements and fixes for markdown diff rendering - #315425
Merged
Matt Bierner (mjbvz) merged 1 commit intoMay 9, 2026
Merged
Conversation
For microsoft#315174 Adding better inline diff indicators
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Markdown diff preview experience by adding richer inline diff indicators in the webview, adjusting initial diff-open scrolling behavior, and refining related styling/state handling in the Markdown preview pipeline.
Changes:
- Introduces
changeIndicatorsmetadata (including original/modified snippet content) and wires it through the diff computation and webview messaging. - Updates the preview’s initial scroll behavior to open at the first detected diff change when no explicit starting scroll is provided.
- Adds new webview-side rendering/styling for deletion/modification indicators (gutter bars + hover tooltips).
Show a summary per file
| File | Description |
|---|---|
| extensions/markdown-language-features/types/previewMessaging.d.ts | Adds MarkdownPreviewChangeIndicator and exposes it via MarkdownPreviewLineChanges. |
| extensions/markdown-language-features/src/preview/topmostLineMonitor.ts | Changes how “previous static editor line” is retrieved (no longer consumes stored value). |
| extensions/markdown-language-features/src/preview/preview.ts | Adds logic to auto-scroll diff previews to the first change on first update. |
| extensions/markdown-language-features/src/preview/lineDiff.ts | Computes and returns changeIndicators as part of modified-side line changes. |
| extensions/markdown-language-features/preview-src/index.ts | Renders change indicators in the preview and generates tooltip diffs (line+token LCS). |
| extensions/markdown-language-features/media/markdown.css | Styles new diff indicators, gutters, and tooltips in the markdown preview. |
Copilot's findings
- Files reviewed: 5/6 changed files
- Comments generated: 7
| const scrollLoc = this.#previousStaticEditorInfo.get(resource); | ||
| this.#previousStaticEditorInfo.delete(resource); | ||
| return scrollLoc?.line; | ||
| return this.#previousStaticEditorInfo.get(resource)?.line; |
Comment on lines
+120
to
+139
| // Collect change indicators for deletions and modifications | ||
| const origChangedCount = origEnd - origStart; | ||
| if (origChangedCount > 0) { | ||
| const originalLines: string[] = []; | ||
| for (let i = origStart; i < origEnd; ++i) { | ||
| originalLines.push(originalDocument.lineAt(i).text); | ||
| } | ||
| const modifiedLines: string[] = []; | ||
| for (let i = modStart; i < modEnd; ++i) { | ||
| modifiedLines.push(modifiedDocument.lineAt(i).text); | ||
| } | ||
| changeIndicators.push({ | ||
| modifiedLine: modStart, | ||
| modifiedLineCount: modEnd - modStart, | ||
| originalLineCount: origChangedCount, | ||
| originalContent: originalLines.join('\n'), | ||
| modifiedContent: modifiedLines.join('\n'), | ||
| type: modEnd === modStart ? 'deletion' : 'modification', | ||
| }); | ||
| } |
| const added = changes.added; | ||
| const innerChanges = changes.modifiedInnerChanges; | ||
| return added.length || innerChanges.length ? { added, innerChanges } : undefined; | ||
| const changeIndicators = options?.includeChangeIndicators === false ? [] : changes.changeIndicators; |
Comment on lines
+423
to
+457
| function createChangeIndicatorElement(indicator: { type: string; originalLineCount: number; originalContent: string; modifiedContent: string }): HTMLDivElement { | ||
| const wrapper = document.createElement('div'); | ||
| wrapper.className = `diff-change-indicator diff-change-indicator-${indicator.type}`; | ||
| wrapper.setAttribute('data-original-line-count', String(indicator.originalLineCount)); | ||
|
|
||
| const arrowLine = document.createElement('span'); | ||
| arrowLine.className = 'diff-change-indicator-arrow'; | ||
| const tooltip = createDiffTooltip(indicator.originalContent, indicator.modifiedContent); | ||
| arrowLine.appendChild(tooltip); | ||
| wrapper.appendChild(arrowLine); | ||
|
|
||
| return wrapper; | ||
| } | ||
|
|
||
| function addModificationGutterBar(element: HTMLElement, indicator?: { originalContent: string; modifiedContent: string }): void { | ||
| const gutter = document.createElement('div'); | ||
| gutter.className = 'diff-modification-gutter'; | ||
|
|
||
| if (indicator) { | ||
| const tooltip = createDiffTooltip(indicator.originalContent, indicator.modifiedContent); | ||
| gutter.appendChild(tooltip); | ||
| } | ||
|
|
||
| element.style.position = 'relative'; | ||
| element.appendChild(gutter); | ||
| } | ||
|
|
||
| function createDiffTooltip(originalContent: string, modifiedContent: string): HTMLDivElement { | ||
| const tooltip = document.createElement('div'); | ||
| tooltip.className = 'diff-change-indicator-tooltip'; | ||
|
|
||
| const originalLines = originalContent ? originalContent.split('\n') : []; | ||
| const modifiedLines = modifiedContent ? modifiedContent.split('\n') : []; | ||
| const lineDiff = computeLineLCS(originalLines, modifiedLines); | ||
|
|
Comment on lines
+446
to
+448
| element.style.position = 'relative'; | ||
| element.appendChild(gutter); | ||
| } |
Comment on lines
+125
to
+147
| /* Transparent hover target over the gutter arrow area */ | ||
| .diff-change-indicator-arrow { | ||
| display: block; | ||
| position: absolute; | ||
| top: -4px; | ||
| left: -12px; | ||
| width: 12px; | ||
| height: 12px; | ||
| cursor: pointer; | ||
| z-index: 2; | ||
| } | ||
|
|
||
| .diff-change-indicator-arrow:hover > .diff-change-indicator-tooltip { | ||
| display: block; | ||
| } | ||
|
|
||
| .diff-change-indicator-arrow > .diff-change-indicator-tooltip { | ||
| left: 8px; | ||
| top: 100%; | ||
| right: auto; | ||
| width: max-content; | ||
| max-width: 80vw; | ||
| } |
Comment on lines
+154
to
+169
| /* Modification indicator uses a subtler style placed after the changed block */ | ||
| .diff-change-indicator-modification { | ||
| height: 2px; | ||
| background: repeating-linear-gradient( | ||
| 90deg, | ||
| var(--vscode-diffEditorGutter-removedLineBackground, var(--vscode-diffEditor-removedTextBackground)) 0px, | ||
| var(--vscode-diffEditorGutter-removedLineBackground, var(--vscode-diffEditor-removedTextBackground)) 4px, | ||
| transparent 4px, | ||
| transparent 8px | ||
| ); | ||
| } | ||
|
|
||
| .diff-change-indicator-modification .diff-change-indicator-arrow { | ||
| background: inherit; | ||
| } | ||
|
|
Alexandru Dima (alexdima)
approved these changes
May 9, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
For #315174