Skip to content

Commit

Permalink
Improve granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jan 22, 2019
1 parent 82aab5a commit d1690ad
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions extensions/html-language-features/server/src/modes/htmlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
doSelection(document: TextDocument, position: Position): Range[] {
const htmlDocument = htmlDocuments.get(document);
let currNode = htmlDocument.findNodeAt(document.offsetAt(position));
let getNodeRange = (n: Node) => {
return Range.create(document.positionAt(n.start), document.positionAt(n.end));
let getNodeRanges = (n: Node) => {
if (n.startTagEnd && n.endTagStart && n.startTagEnd < n.endTagStart) {
return [
Range.create(document.positionAt(n.startTagEnd), document.positionAt(n.endTagStart)),
Range.create(document.positionAt(n.start), document.positionAt(n.end)),
];
}

return [Range.create(document.positionAt(n.start), document.positionAt(n.end))];
};
const result = [getNodeRange(currNode)];
const result = [...getNodeRanges(currNode)];

while (currNode.parent) {
currNode = currNode.parent;
result.push(getNodeRange(currNode));
getNodeRanges(currNode).forEach(r => result.push(r));
}

return result;
Expand Down

0 comments on commit d1690ad

Please sign in to comment.