Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/preview-src/activeLineMarker.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { getElementsForSourceLine } from './scroll-sync';
6
7
export class ActiveLineMarker {
8
private _current: any;
9
10
onDidChangeTextEditorSelection(line: number, documentVersion: number) {
11
const { previous } = getElementsForSourceLine(line, documentVersion);
12
this._update(previous && (previous.codeElement || previous.element));
13
}
14
15
private _update(before: HTMLElement | undefined) {
16
this._unmarkActiveElement(this._current);
17
this._markActiveElement(before);
18
this._current = before;
19
}
20
21
private _unmarkActiveElement(element: HTMLElement | undefined) {
22
if (!element) {
23
return;
24
}
25
element.classList.toggle('code-active-line', false);
26
}
27
28
private _markActiveElement(element: HTMLElement | undefined) {
29
if (!element) {
30
return;
31
}
32
33
element.classList.toggle('code-active-line', true);
34
}
35
}
36
37