forked from asciidoctor/asciidoctor-vscode
/
activeLineMarker.ts
33 lines (28 loc) · 1.01 KB
/
activeLineMarker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*---------------------------------------------------------------------------------------------
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { getElementsForSourceLine } from './scroll-sync';
export class ActiveLineMarker {
private _current: any;
onDidChangeTextEditorSelection(line: number) {
const { previous } = getElementsForSourceLine(line);
this._update(previous && previous.element);
}
_update(before: HTMLElement | undefined) {
this._unmarkActiveElement(this._current);
this._markActiveElement(before);
this._current = before;
}
_unmarkActiveElement(element: HTMLElement | undefined) {
if (!element) {
return;
}
element.className = element.className.replace(/\bcode-active-line\b/g, '');
}
_markActiveElement(element: HTMLElement | undefined) {
if (!element) {
return;
}
element.className += ' code-active-line';
}
}