Skip to content

Commit 915e1eb

Browse files
committed
Return if there was parsing error
1 parent fc6c693 commit 915e1eb

7 files changed

Lines changed: 23 additions & 4 deletions

File tree

extensions/emmet/src/balance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ function balance(out: boolean) {
3030
let getRangeFunction = out ? getRangeToBalanceOut : getRangeToBalanceIn;
3131

3232
let rootNode: HtmlNode = parse(new DocumentStreamReader(editor.document));
33+
if (!rootNode) {
34+
return;
35+
}
3336

3437
let newSelections: vscode.Selection[] = [];
3538
editor.selections.forEach(selection => {

extensions/emmet/src/matchTag.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function matchTag() {
1717
}
1818

1919
let rootNode: HtmlNode = parse(new DocumentStreamReader(editor.document));
20+
if (!rootNode) {
21+
return;
22+
}
2023
let updatedSelections = [];
2124
editor.selections.forEach(selection => {
2225
let updatedSelection = getUpdatedSelections(editor, selection.start, rootNode);
@@ -38,7 +41,8 @@ function getUpdatedSelections(editor: vscode.TextEditor, position: vscode.Positi
3841
return;
3942
}
4043

41-
let finalPosition = position.isBeforeOrEqual(currentNode.open.end) ? currentNode.close.start : currentNode.open.start;
44+
// Place cursor inside the close tag if cursor is inside the open tag, else place it inside the open tag
45+
let finalPosition = position.isBeforeOrEqual(currentNode.open.end) ? currentNode.close.start.translate(0, 2) : currentNode.open.start.translate(0, 1);
4246
return new vscode.Selection(finalPosition, finalPosition);
4347
}
4448

extensions/emmet/src/mergeLines.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function mergeLines() {
2121
}
2222

2323
let rootNode: Node = parse(new DocumentStreamReader(editor.document));
24-
24+
if (!rootNode) {
25+
return;
26+
}
2527
editor.edit(editBuilder => {
2628
editor.selections.reverse().forEach(selection => {
2729
let [rangeToReplace, textToReplaceWith] = getRangesToReplace(editor.document, selection, rootNode);

extensions/emmet/src/selectItem.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export function fetchSelectItem(direction: string): void {
3535
}
3636

3737
let rootNode: Node = parseContent(new DocumentStreamReader(editor.document));
38+
if (!rootNode) {
39+
return;
40+
}
3841
let newSelections: vscode.Selection[] = [];
3942
editor.selections.forEach(selection => {
4043
const selectionStart = selection.isReversed ? selection.active : selection.anchor;

extensions/emmet/src/splitJoinTag.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function splitJoinTag() {
2121
}
2222

2323
let rootNode: Node = parse(new DocumentStreamReader(editor.document));
24-
24+
if (!rootNode) {
25+
return;
26+
}
2527
editor.edit(editBuilder => {
2628
editor.selections.reverse().forEach(selection => {
2729
let [rangeToReplace, textToReplaceWith] = getRangesToReplace(editor.document, selection, rootNode);

extensions/emmet/src/toggleComment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export function toggleComment() {
4141
}
4242

4343
let rootNode = parseContent(new DocumentStreamReader(editor.document));
44-
44+
if (!rootNode) {
45+
return;
46+
}
4547
editor.edit(editBuilder => {
4648
editor.selections.reverse().forEach(selection => {
4749
let [rangesToUnComment, rangeToComment] = toggleCommentInternal(editor.document, selection, rootNode);

extensions/emmet/src/updateTag.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function updateTag(tagName: string) {
1717
}
1818

1919
let rootNode: HtmlNode = parse(new DocumentStreamReader(editor.document));
20+
if (!rootNode) {
21+
return;
22+
}
2023
let rangesToUpdate = [];
2124
editor.selections.reverse().forEach(selection => {
2225
rangesToUpdate = rangesToUpdate.concat(getRangesToUpdate(editor, selection, rootNode));

0 commit comments

Comments
 (0)