Complete Home key toggle functionality between line start and indentation#199
Complete Home key toggle functionality between line start and indentation#199lhecker merged 3 commits intomicrosoft:mainfrom achaljhawar:main
Conversation
src/tui.rs
Outdated
| // If the cursor is at the start of the line (column 0), move it to the indentation position | ||
| else if logical_after.x == 0 && indent_end.x > 0 { |
There was a problem hiding this comment.
Now that I'm looking at this code, I notice that indent_end is only needed if logical_after.x == 0. Do you mind wrapping both if conditions into a single block like this?
if logical_after.x == 0 {
let indent_end = tb.indent_end_logical_pos();
if logical_before > indent_end {
// ...
} else if indent_end.x > 0 {
// ...
}
}The reason for this is that seeking backwards in the buffer is a lot more expensive than seeking forwards. This means that indent_end_logical_pos is an "expensive" call (relatively speaking) if the current cursor is not at the line start. logical_after.x == 0 means that the cursor is at the line start and so that means the call is cheap.
lhecker
left a comment
There was a problem hiding this comment.
Wait, I just tested your changes, and they unfortunately don't work. 😅
| // we move it back to the end of the indentation. | ||
| if logical_after.x == 0 | ||
| && let indent_end = tb.indent_end_logical_pos() | ||
| && (logical_before > indent_end || logical_before.x == 0) |
There was a problem hiding this comment.
Because I was curious about it, I tried implementing it myself. The correct approach is checking for logical_before.x == 0.
I also made the optimization I described above, by moving the indent_end_logical_pos call into the let chain.
…tion (microsoft#199) Closes microsoft#81 Co-authored-by: Leonard Hecker <leonard@hecker.io>
Complete Home key toggle functionality
Problem (#81)
Edit has a "smart home" feature that moves from text to indentation to column 0, but lacks the ability to move from column 0 back to indentation when pressing Home.
Solution
This PR completes the bidirectional toggle behavior by adding the missing functionality to move from column 0 to the first non-whitespace character, matching VSCode and Visual Studio behavior.
Implementation
indent_end_logical_pos()functionFiles Changed
src/tui.rs: Added missing condition in Home key handlerTesting
Verified toggle works in both directions with and without selection.