Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/emmet/src/selectItem.ts
5240 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
6
import * as vscode from 'vscode';
7
import { validate, isStyleSheet } from './util';
8
import { nextItemHTML, prevItemHTML } from './selectItemHTML';
9
import { nextItemStylesheet, prevItemStylesheet } from './selectItemStylesheet';
10
import { HtmlNode, CssNode } from 'EmmetFlatNode';
11
import { getRootNode } from './parseDocument';
12
13
export function fetchSelectItem(direction: string): void {
14
if (!validate() || !vscode.window.activeTextEditor) {
15
return;
16
}
17
const editor = vscode.window.activeTextEditor;
18
const document = editor.document;
19
const rootNode = getRootNode(document, true);
20
if (!rootNode) {
21
return;
22
}
23
24
const newSelections: vscode.Selection[] = [];
25
editor.selections.forEach(selection => {
26
const selectionStart = selection.isReversed ? selection.active : selection.anchor;
27
const selectionEnd = selection.isReversed ? selection.anchor : selection.active;
28
29
let updatedSelection;
30
if (isStyleSheet(editor.document.languageId)) {
31
updatedSelection = direction === 'next' ?
32
nextItemStylesheet(document, selectionStart, selectionEnd, <CssNode>rootNode) :
33
prevItemStylesheet(document, selectionStart, selectionEnd, <CssNode>rootNode);
34
} else {
35
updatedSelection = direction === 'next' ?
36
nextItemHTML(document, selectionStart, selectionEnd, <HtmlNode>rootNode) :
37
prevItemHTML(document, selectionStart, selectionEnd, <HtmlNode>rootNode);
38
}
39
newSelections.push(updatedSelection ? updatedSelection : selection);
40
});
41
editor.selections = newSelections;
42
editor.revealRange(editor.selections[editor.selections.length - 1]);
43
}
44
45