Skip to content

Commit 31da28a

Browse files
committed
Don't output lines with no annotations
1 parent aa95401 commit 31da28a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,32 @@ export function serializeTargetRange(
3636
const lines: string[] = [];
3737

3838
codeLines.forEach((codeLine, lineNumber) => {
39-
// Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
40-
lines.push(
41-
codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`,
42-
);
43-
39+
let annotationLine: string | undefined;
4440
if (lineNumber === start.line) {
4541
const prefix = fill(" ", start.character + 2) + ">";
4642
if (start.line === end.line) {
47-
lines.push(prefix + fill("-", end.character - start.character) + "<");
43+
annotationLine =
44+
prefix + fill("-", end.character - start.character) + "<";
4845
} else {
49-
lines.push(prefix + fill("-", codeLine.length - start.character));
46+
annotationLine = prefix + fill("-", codeLine.length - start.character);
5047
}
5148
} else if (lineNumber > start.line && lineNumber < end.line) {
5249
if (codeLine.length > 0) {
53-
lines.push(" " + fill("-", codeLine.length));
50+
annotationLine = " " + fill("-", codeLine.length);
5451
} else {
55-
lines.push("");
52+
annotationLine = "";
5653
}
5754
} else if (lineNumber === end.line) {
58-
lines.push(" " + fill("-", end.character) + "<");
59-
} else {
60-
lines.push("");
55+
annotationLine = " " + fill("-", end.character) + "<";
56+
}
57+
58+
if (annotationLine != null) {
59+
// Only output anything if there is an annotation line
60+
lines.push(
61+
// Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
62+
codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`,
63+
annotationLine,
64+
);
6165
}
6266
});
6367

0 commit comments

Comments
 (0)