Fix #173869 marking active line for code elements too in markdown pre… (#173870)

Fix #173869 marking active line for code elements too in markdown preview
This commit is contained in:
Ely Ronnen 2023-02-08 22:25:54 +02:00 committed by GitHub
parent 646de5e063
commit 5b79b91838
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

@ -9,7 +9,7 @@ export class ActiveLineMarker {
onDidChangeTextEditorSelection(line: number, documentVersion: number) {
const { previous } = getElementsForSourceLine(line, documentVersion);
this._update(previous && previous.element);
this._update(previous && (previous.codeElement || previous.element));
}
_update(before: HTMLElement | undefined) {
@ -22,13 +22,14 @@ export class ActiveLineMarker {
if (!element) {
return;
}
element.className = element.className.replace(/\bcode-active-line\b/g, '');
element.classList.toggle('code-active-line', false);
}
_markActiveElement(element: HTMLElement | undefined) {
if (!element) {
return;
}
element.className += ' code-active-line';
element.classList.toggle('code-active-line', true);
}
}

View file

@ -11,6 +11,7 @@ const codeLineClass = 'code-line';
export interface CodeLineElement {
element: HTMLElement;
line: number;
codeElement?: HTMLElement;
}
const getCodeLineElements = (() => {
@ -27,9 +28,9 @@ const getCodeLineElements = (() => {
}
if (element.tagName === 'CODE' && element.parentElement && element.parentElement.tagName === 'PRE') {
// Fenched code blocks are a special case since the `code-line` can only be marked on
// Fenced code blocks are a special case since the `code-line` can only be marked on
// the `<code>` element and not the parent `<pre>` element.
cachedElements.push({ element: element.parentElement as HTMLElement, line });
cachedElements.push({ element: element.parentElement as HTMLElement, line: line, codeElement: element as HTMLElement });
} else if (element.tagName === 'UL' || element.tagName === 'OL') {
// Skip adding list elements since the first child has the same code line (and should be preferred)
} else {