Skip to content

Improve the behaviour of Home in non-vim mode#639

Merged
dzhou121 merged 2 commits intolapce:masterfrom
DJMcNab:home_2
Jun 18, 2022
Merged

Improve the behaviour of Home in non-vim mode#639
dzhou121 merged 2 commits intolapce:masterfrom
DJMcNab:home_2

Conversation

@DJMcNab
Copy link
Copy Markdown
Contributor

@DJMcNab DJMcNab commented Jun 18, 2022

Previously, pressing Home would always return to the first non-indent character

However, a nicer behaviour once you are at that character is to move to the start of the line instead.
This is consistent with the behaviour of vscode.

Previously, pressing <kbd>Home</kbd> would
always return to the first non-indent character

However, a nicer behaviour once you are at that
character is to move to the start of the line instead
let line = self.buffer.line_of_offset(offset);
let new_offset = self.buffer.first_non_blank_character_on_line(line);
(new_offset, Some(ColPosition::FirstNonBlank))
if offset == new_offset {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe it should be if offset <= new_offset ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, the reason for this version is that if your line is

<|>    blah

and you press home, the correct behaviour is to make your cursor move to:

    <|>blah

At least, that's what vscode does.
Basically, pressing home should cycle between the two states, defaulting to the first non-whitespace character.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I just tested VSCode,

If the cursor is at the left of the first non-whitespace character, Home gets to the line beginning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, great. I'll implement that version then

@dzhou121
Copy link
Copy Markdown
Collaborator

Thanks!

@dzhou121 dzhou121 merged commit 46ca3bb into lapce:master Jun 18, 2022
@DJMcNab DJMcNab deleted the home_2 branch June 18, 2022 18:38
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