Skip to content
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

Fixed multiline selection issue in edit mode #4514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jazzcort
Copy link

@Jazzcort Jazzcort commented Mar 6, 2025

Description

The original behavior was only selecting the highlighted part and if there is nothing selected in the trailing line it still got seleced to the edit mode. This fix is to expand the selection start to the very beginning of first line and the selection end to the very end of the last line. In addtion, prevent the trailing line getting selecting if there is nothing in it.
Granite-Code/granite-code#42

Testing instructions

  1. Partially select the first line and then Cmd-I, and check if the entire first line get selected in the editor and display correctly in the edit mode section.
  2. Select empty trailing line and then Cmd-I, and check if the trailing line not get selected in the editor and not include in the display of the edit mode section.

Copy link

netlify bot commented Mar 6, 2025

Deploy Preview for continuedev canceled.

Name Link
🔨 Latest commit 742ca31
🔍 Latest deploy log https://app.netlify.com/sites/continuedev/deploys/67cb437c65391e0008e0e3fe

Copy link
Contributor

@owtaylor owtaylor left a comment

Choose a reason for hiding this comment

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

This looks like it will fix the problem I identified. I see a few style things that could be improved.

selectionStart = editor.selection.end;
selectionEnd = editor.selection.start;
} else if (selectionStart.line === selectionEnd.line) {
if (selectionStart.character > selectionEnd.character) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would read better if it was:

if (selectionStart.line > selectionEnd.line || (selectionStart.line == selectionEnd.line && ...)) {
      selectionStart = editor.selection.end;
      selectionEnd = editor.selection.start;
} else {
    ...
}

const startFromCharZero = new vscode.Position(selectionStart.line, 0);
const document = editor.document;
let lastLine, lastChar;
// Check if there is a trailing line
Copy link
Contributor

Choose a reason for hiding this comment

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

What this comment should include is not what its doing but why, so more like:

// 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.

@@ -534,9 +534,38 @@ 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.

@Jazzcort Jazzcort force-pushed the Jazzcort/multiline-edit-selection branch 4 times, most recently from 43b168a to c38606b Compare March 7, 2025 16:04
The original behavior was only selecting the highlighted part
and if there is nothing selected in the trailing line it still
got seleced to the edit mode. This fix is to expand the
selection start to the very beginning of first line and the
selection end to the very end of the last line. In addtion,
prevent the trailing line getting selecting if there is
nothing in it.
Granite-Code/granite-code#42
@Jazzcort Jazzcort force-pushed the Jazzcort/multiline-edit-selection branch from c38606b to 742ca31 Compare March 7, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants