Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions extensions/markdown-language-features/media/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ body.showEditorSelection .code-line {
position: relative;
}

.code-line-diff {
border-radius: 2px;
box-shadow: -4px 0 0 transparent;
}

.code-line-diff-added {
background-color: var(--vscode-diffEditor-insertedTextBackground);
box-shadow: -4px 0 0 var(--vscode-diffEditorGutter-insertedLineBackground);
}

.code-line-diff-deleted {
background-color: var(--vscode-diffEditor-removedTextBackground);
box-shadow: -4px 0 0 var(--vscode-diffEditorGutter-removedLineBackground);
}

.vscode-high-contrast .code-line-diff-added {
outline: 1px solid var(--vscode-diffEditor-insertedTextBorder);
}

.vscode-high-contrast .code-line-diff-deleted {
outline: 1px solid var(--vscode-diffEditor-removedTextBorder);
}

body.showEditorSelection :not(tr,ul,ol).code-active-line:before,
body.showEditorSelection :not(tr,ul,ol).code-line:hover:before {
content: "";
Expand Down
7 changes: 5 additions & 2 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"publisher": "vscode",
"license": "MIT",
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
"enabledApiProposals": [
"customEditorDiffs"
],
"engines": {
"vscode": "^1.70.0"
},
Expand Down Expand Up @@ -156,7 +159,7 @@
"command": "markdown.showSource",
"title": "%markdown.showSource.title%",
"category": "Markdown",
"icon": "$(go-to-file)"
"icon": "$(file-text)"
},
{
"command": "markdown.showPreviewSecuritySelector",
Expand Down Expand Up @@ -188,7 +191,7 @@
"command": "markdown.reopenAsSource",
"title": "%markdown.reopenAsSource.title%",
"category": "Markdown",
"icon": "$(go-to-file)"
"icon": "$(file-text)"
},
{
"command": "markdown.togglePreview",
Expand Down
32 changes: 30 additions & 2 deletions extensions/markdown-language-features/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import { ActiveLineMarker } from './activeLineMarker';
import { onceDocumentLoaded } from './events';
import { createPosterForVsCode } from './messaging';
import { getEditorLineNumberForPageOffset, scrollToRevealSourceLine, getLineElementForFragment } from './scroll-sync';
import { getEditorLineNumberForPageOffset, getElementsForSourceLine, getLineElementForFragment, scrollToRevealSourceLine } from './scroll-sync';
import { SettingsManager, getData, getRawData } from './settings';
import throttle = require('lodash.throttle');
import morphdom from 'morphdom';
import type { ToWebviewMessage } from '../types/previewMessaging';
import type { MarkdownPreviewLineChanges, ToWebviewMessage } from '../types/previewMessaging';
import { isOfScheme, Schemes } from '../src/util/schemes';

let scrollDisabledCount = 0;
Expand All @@ -21,6 +21,7 @@ const settings = new SettingsManager();

let documentVersion = 0;
let documentResource = settings.settings.source;
let lineChanges = settings.settings.lineChanges;

const vscode = acquireVsCodeApi();

Expand Down Expand Up @@ -88,6 +89,7 @@ onceDocumentLoaded(() => {
// Restore
const scrollProgress = state.scrollProgress;
addImageContexts();
applyLineChanges(lineChanges);
if (typeof scrollProgress === 'number' && !settings.settings.fragment) {
doAfterImagesLoaded(() => {
scrollDisabledCount = 1;
Expand Down Expand Up @@ -243,6 +245,7 @@ window.addEventListener('message', async event => {
return;

case 'updateContent': {
lineChanges = data.lineChanges;
const root = document.querySelector('.markdown-body')!;

const parser = new DOMParser();
Expand Down Expand Up @@ -314,11 +317,36 @@ window.addEventListener('message', async event => {

window.dispatchEvent(new CustomEvent('vscode.markdown.updateContent'));
addImageContexts();
applyLineChanges(lineChanges);
break;
}
}
}, false);

function applyLineChanges(lineChanges: MarkdownPreviewLineChanges | undefined): void {
for (const element of document.querySelectorAll('.code-line-diff-added, .code-line-diff-deleted')) {
element.classList.remove('code-line-diff', 'code-line-diff-added', 'code-line-diff-deleted');
}

markChangedLines(lineChanges?.added, 'code-line-diff-added');
markChangedLines(lineChanges?.deleted, 'code-line-diff-deleted');
}

function markChangedLines(lines: readonly number[] | undefined, className: string): void {
if (!lines) {
return;
}

for (const line of lines) {
const { previous, next } = getElementsForSourceLine(line, documentVersion);
const lineElement = previous.line >= 0 ? previous : next;
const element = lineElement?.codeElement || lineElement?.element;
if (element) {
element.classList.add('code-line-diff', className);
}
}
}



document.addEventListener('dblclick', event => {
Expand Down
3 changes: 3 additions & 0 deletions extensions/markdown-language-features/preview-src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { MarkdownPreviewLineChanges } from '../types/previewMessaging';

export interface PreviewSettings {
readonly source: string;
readonly line?: number;
readonly fragment?: string;
readonly selectedLine?: number;
readonly lineChanges?: MarkdownPreviewLineChanges;

readonly scrollPreviewWithEditor?: boolean;
readonly scrollEditorWithPreview: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { WebviewResourceProvider } from '../util/resources';
import { generateUuid } from '../util/uuid';
import { MarkdownPreviewConfiguration, MarkdownPreviewConfigurationManager } from './previewConfig';
import { ContentSecurityPolicyArbiter, MarkdownPreviewSecurityLevel } from './security';
import type { MarkdownPreviewLineChanges } from '../../types/previewMessaging';


/**
Expand Down Expand Up @@ -76,6 +77,7 @@ export class MdDocumentRenderer {
selectedLine: number | undefined,
state: any | undefined,
imageInfo: readonly ImageInfo[],
lineChanges: MarkdownPreviewLineChanges | undefined,
token: vscode.CancellationToken
): Promise<MarkdownContentProviderOutput> {
const sourceUri = markdownDocument.uri;
Expand All @@ -85,6 +87,7 @@ export class MdDocumentRenderer {
fragment: state?.fragment || markdownDocument.uri.fragment || undefined,
line: initialLine,
selectedLine,
lineChanges,
scrollPreviewWithEditor: config.scrollPreviewWithEditor,
scrollEditorWithPreview: config.scrollEditorWithPreview,
doubleClickToSwitchToEditor: config.doubleClickToSwitchToEditor,
Expand Down
Loading
Loading