From 198d9b32990a332aa5cc12636d131974ee2310bf Mon Sep 17 00:00:00 2001 From: killian Date: Sat, 15 Oct 2022 20:35:26 +0200 Subject: [PATCH] Improve Ctrl+Left-Arrow Keys behavior (#1531) * Improve Ctrl+Left-Arrow Keys behavior * Add CHANGELOG entry --- CHANGELOG.md | 3 ++- lapce-core/src/word.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2889d04e..69c4819d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features/Changes +- [#1531](https://github.com/lapce/lapce/pull/1531): Improved Ctrl+Left command on spaces at the beginning of a line - [#1491](https://github.com/lapce/lapce/pull/1491): Added Vim shift+c to delete remainder of line - [#1508](https://github.com/lapce/lapce/pull/1508): Show in progress when Lapce is self updating - [#1475](https://github.com/lapce/lapce/pull/1475): Add editor setting: "Cursor Surrounding Lines" which sets minimum number of lines above and below cursor @@ -106,4 +107,4 @@ - [#1191](https://github.com/lapce/lapce/pull/1191): Tone down default inlay hint background color in Lapce dark theme - [#1227](https://github.com/lapce/lapce/pull/1227): Don't restore cursor mode on undo - [#1413](https://github.com/lapce/lapce/pull/1413): Disable format-on-save by default. Remember to re-enable this if you want it! -- [#1404](https://github.com/lapce/lapce/pull/1404): Log panics with full backtrace as error \ No newline at end of file +- [#1404](https://github.com/lapce/lapce/pull/1404): Log panics with full backtrace as error diff --git a/lapce-core/src/word.rs b/lapce-core/src/word.rs index c2934943..a9e8e511 100644 --- a/lapce-core/src/word.rs +++ b/lapce-core/src/word.rs @@ -78,6 +78,14 @@ pub fn prev_boundary(&mut self) -> Option { if classify_boundary(prop_prev, prop).is_start() { break; } + + // Stop if line beginning reached, without any non-whitespace characters + if prop_prev == CharClassification::Lf + && prop == CharClassification::Space + { + break; + } + prop = prop_prev; candidate = self.inner.pos(); } @@ -469,6 +477,14 @@ fn prev_boundary_should_be_at_word_start() { assert_eq!(boundary, Some(6)); } + #[test] + fn on_whitespace_prev_boundary_should_be_at_line_start() { + let rope = Rope::from("Hello\n world"); + let mut cursor = WordCursor::new(&rope, 10); + let boundary = cursor.prev_boundary(); + assert_eq!(boundary, Some(6)); + } + #[test] fn should_get_next_word_boundary() { let rope = Rope::from("Hello world");