diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 9b2dd68ba..0f9bfc143 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -551,9 +551,26 @@ const getCommandsMap: ( return; } + const startFromCharZero = editor.selection.start.with(undefined, 0); + const document = editor.document; + let lastLine, lastChar; + // If the user selected onto a trailing line but didn't actually include any characters in it + // they don't want to include that line, so trim it off. + if (editor.selection.end.character === 0) { + // This is to prevent the rare case that the previous line gets selected when user + // is selecting nothing and the cursor is at the beginning of the line + if (editor.selection.end.line === editor.selection.start.line) { + lastLine = editor.selection.start.line; + } else { + lastLine = editor.selection.end.line - 1; + } + } else { + lastLine = editor.selection.end.line; + } + lastChar = document.lineAt(lastLine).range.end.character; + const endAtCharLast = new vscode.Position(lastLine, lastChar); const range = - args?.range ?? - new vscode.Range(editor.selection.start, editor.selection.end); + args?.range ?? new vscode.Range(startFromCharZero, endAtCharLast); editDecorationManager.setDecoration(editor, range);