@@ -2632,6 +2632,18 @@ pub mod insert {
26322632 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
26332633 pub type PostHook = fn(&mut Context, char);
26342634
2635+ /// Exclude the cursor in range.
2636+ fn exclude_cursor(text: RopeSlice, range: Range, cursor: Range) -> Range {
2637+ if range.to() == cursor.to() {
2638+ Range::new(
2639+ range.from(),
2640+ graphemes::prev_grapheme_boundary(text, cursor.to()),
2641+ )
2642+ } else {
2643+ range
2644+ }
2645+ }
2646+
26352647 // It trigger completion when idle timer reaches deadline
26362648 // Only trigger completion if the word under cursor is longer than n characters
26372649 pub fn idle_completion(cx: &mut Context) {
@@ -2948,10 +2960,11 @@ pub mod insert {
29482960 let (view, doc) = current!(cx.editor);
29492961 let text = doc.text().slice(..);
29502962
2951− let selection = doc
2952− .selection(view.id)
2953− .clone()
2954− .transform(|range| movement::move_prev_word_start(text, range, count));
2963+ let selection = doc.selection(view.id).clone().transform(|range| {
2964+ let cursor = Range::point(range.cursor(text));
2965+ let next = movement::move_prev_word_start(text, cursor, count);
2966+ exclude_cursor(text, next, range)
2967+ });
29552968 delete_selection_insert_mode(doc, view, &selection);
29562969 }
29572970