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

Fix cursor movement on selections with arrow keys #1911

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [#1835](https://github.com/lapce/lapce/pull/1835): Add mouse keybinds

### Bug Fixes
- [#1911](https://github.com/lapce/lapce/pull/1911): Fix movement on selections with left/right arrow keys

## 0.2.5

Expand Down
24 changes: 24 additions & 0 deletions lapce-data/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,30 @@ impl Document {
view: &EditorView,
config: &LapceConfig,
) -> SelRegion {
let (count, region) = if count >= 1 && !modify && !region.is_caret() {
// If we're not a caret, and we are moving left or right, we want to move
// the cursor to the left or right side of the selection.
// Ex: `|abc|` -> left arrow key -> `|abc`
// Ex: `|abc|` -> right arrow key -> `abc|`
// and it doesn't matter which direction the selection os going, so we use min/max
match movement {
Movement::Left => {
let leftmost = region.min();
(count - 1, SelRegion::new(leftmost, leftmost, region.horiz))
}
Movement::Right => {
let rightmost = region.max();
(
count - 1,
SelRegion::new(rightmost, rightmost, region.horiz),
)
}
_ => (count, *region),
}
} else {
(count, *region)
};

let (end, horiz) = self.move_offset(
text,
region.end,
Expand Down