summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tham2021-06-08 13:50:33 +0000
committerBlaž Hrastnik2021-06-08 14:08:08 +0000
commit5e2ba28e0e3e872609398f1f3cee0c5b82207de0 (patch)
treea9124e88f5dfa72a03dae25911c21f4d3d316b63
parent83723957fe8a1f4b87b4590fc64dce941e162637 (diff)
Fix panic on ctrl-w empty document
-rw-r--r--helix-core/src/words.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/helix-core/src/words.rs b/helix-core/src/words.rs
index 2cbd88d4..7ecdacba 100644
--- a/helix-core/src/words.rs
+++ b/helix-core/src/words.rs
@@ -25,7 +25,7 @@ pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usiz
}
}
- if with_end {
+ if with_end || char_idx == 0 {
char_idx
} else {
char_idx + 1
@@ -37,7 +37,7 @@ fn different_prev_word_boundary() {
use ropey::Rope;
let t = |x, y| {
let text = Rope::from(x);
- let out = nth_prev_word_boundary(text.slice(..), text.len_chars() - 1, 1);
+ let out = nth_prev_word_boundary(text.slice(..), text.len_chars().saturating_sub(1), 1);
assert_eq!(text.slice(..out), y, r#"from "{}""#, x);
};
t("abcd\nefg\nwrs", "abcd\nefg\n");
@@ -47,6 +47,7 @@ fn different_prev_word_boundary() {
t("hello, world", "hello, ");
t("hello, ", "hello");
t("hello", "");
+ t(",", "");
t("こんにちは、世界!", "こんにちは、世界");
t("こんにちは、世界", "こんにちは、");
t("こんにちは、", "こんにちは");
@@ -56,10 +57,12 @@ fn different_prev_word_boundary() {
t("お前はもう死んでいる", "");
t("その300円です", ""); // TODO: should stop at 300
t("唱k", ""); // TODO: should stop at 唱
+ t(",", "");
t("1 + 1 = 2", "1 + 1 = ");
t("1 + 1 =", "1 + 1 ");
t("1 + 1", "1 + ");
t("1 + ", "1 ");
t("1 ", "");
t("1+1=2", "1+1=");
+ t("", "");
}