@@ -25,7 +25,7 @@ pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usiz
2525 }
2626 }
2727
28− if with_end {
28+ if with_end || char_idx == 0 {
2929 char_idx
3030 } else {
3131 char_idx + 1
@@ -37,7 +37,7 @@ fn different_prev_word_boundary() {
3737 use ropey::Rope;
3838 let t = |x, y| {
3939 let text = Rope::from(x);
40− let out = nth_prev_word_boundary(text.slice(..), text.len_chars() - 1, 1);
40+ let out = nth_prev_word_boundary(text.slice(..), text.len_chars().saturating_sub(1), 1);
4141 assert_eq!(text.slice(..out), y, r#"from "{}""#, x);
4242 };
4343 t("abcd\nefg\nwrs", "abcd\nefg\n");
@@ -47,6 +47,7 @@ fn different_prev_word_boundary() {
4747 t("hello, world", "hello, ");
4848 t("hello, ", "hello");
4949 t("hello", "");
50+ t(",", "");
5051 t("こんにちは、世界!", "こんにちは、世界");
5152 t("こんにちは、世界", "こんにちは、");
5253 t("こんにちは、", "こんにちは");
@@ -56,10 +57,12 @@ fn different_prev_word_boundary() {
5657 t("お前はもう死んでいる", "");
5758 t("その300円です", ""); // TODO: should stop at 300
5859 t("唱k", ""); // TODO: should stop at 唱
60+ t(",", "");
5961 t("1 + 1 = 2", "1 + 1 = ");
6062 t("1 + 1 =", "1 + 1 ");
6163 t("1 + 1", "1 + ");
6264 t("1 + ", "1 ");
6365 t("1 ", "");
6466 t("1+1=2", "1+1=");
67+ t("", "");
6568}