From a34afcb1f8c55c96c9ddd3daf642ae8b3fcdc909 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:32:44 +0000 Subject: [PATCH] Don't output lines with no annotations --- .../src/suite/serializeTargetRange.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts b/packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts index 13f5360478d..2ac04ce8504 100644 --- a/packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts +++ b/packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts @@ -36,28 +36,32 @@ export function serializeTargetRange( const lines: string[] = []; codeLines.forEach((codeLine, lineNumber) => { - // Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"` - lines.push( - codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`, - ); - + let annotationLine: string | undefined; if (lineNumber === start.line) { const prefix = fill(" ", start.character + 2) + ">"; if (start.line === end.line) { - lines.push(prefix + fill("-", end.character - start.character) + "<"); + annotationLine = + prefix + fill("-", end.character - start.character) + "<"; } else { - lines.push(prefix + fill("-", codeLine.length - start.character)); + annotationLine = prefix + fill("-", codeLine.length - start.character); } } else if (lineNumber > start.line && lineNumber < end.line) { if (codeLine.length > 0) { - lines.push(" " + fill("-", codeLine.length)); + annotationLine = " " + fill("-", codeLine.length); } else { - lines.push(""); + annotationLine = ""; } } else if (lineNumber === end.line) { - lines.push(" " + fill("-", end.character) + "<"); - } else { - lines.push(""); + annotationLine = " " + fill("-", end.character) + "<"; + } + + if (annotationLine != null) { + // Only output any thing if there is an annotation line + lines.push( + // Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"` + codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`, + annotationLine, + ); } });