Skip to content

Fixed multiline selection issue in edit mode #4514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,26 @@ const getCommandsMap: (
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The should be some sort of comment here about what this is all about, would suggest:

// Edits are always of complete lines - we want to be consistent for that when we highlight,
// show the range in the sidebar, or send it to the model. To simplify, this, expand the range
// here to be complete lines.

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);

Expand Down
Loading