Skip to content

Various improvements and fixes for markdown diff rendering - #315425

Merged
Matt Bierner (mjbvz) merged 1 commit into
microsoft:mainfrom
mjbvz:dev/mjbvz/regional-nightingale
May 9, 2026
Merged

Matt Bierner (mjbvz) merged 1 commit into
microsoft:mainfrom
mjbvz:dev/mjbvz/regional-nightingale

Conversation

@mjbvz

Copy link
Copy Markdown
Contributor

For #315174

  • Adding better inline diff indicators
  • Fixing starting line when you open the diff
  • Styling improvements

Copilot AI review requested due to automatic review settings May 9, 2026 02:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 changeIndicators metadata (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;
}

@mjbvz
Matt Bierner (mjbvz) merged commit c60ffe9 into microsoft:main May 9, 2026
28 of 29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 9, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants