From 6c038bb0151c6aeb43fc94bd2dc3d516a71d346c Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sun, 18 Jul 2021 21:59:31 -0700 Subject: Update word selection/navigation to work with gap indexing. Also tweaked some of the existing behavior that seemed inconsistent and/or buggy. It's mostly identical, just a few corner cases are different. --- helix-term/src/commands.rs | 75 +++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 27 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 41b342b2..1f84db6b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -498,6 +498,7 @@ fn move_next_word_start(cx: &mut Context) { view.id, doc.selection(view.id) .clone() + .min_width_1(doc.text().slice(..)) .transform(|range| movement::move_next_word_start(doc.text().slice(..), range, count)), ); } @@ -509,6 +510,7 @@ fn move_prev_word_start(cx: &mut Context) { view.id, doc.selection(view.id) .clone() + .min_width_1(doc.text().slice(..)) .transform(|range| movement::move_prev_word_start(doc.text().slice(..), range, count)), ); } @@ -520,6 +522,7 @@ fn move_next_word_end(cx: &mut Context) { view.id, doc.selection(view.id) .clone() + .min_width_1(doc.text().slice(..)) .transform(|range| movement::move_next_word_end(doc.text().slice(..), range, count)), ); } @@ -529,9 +532,12 @@ fn move_next_long_word_start(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - movement::move_next_long_word_start(doc.text().slice(..), range, count) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + movement::move_next_long_word_start(doc.text().slice(..), range, count) + }), ); } @@ -540,9 +546,12 @@ fn move_prev_long_word_start(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - movement::move_prev_long_word_start(doc.text().slice(..), range, count) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + movement::move_prev_long_word_start(doc.text().slice(..), range, count) + }), ); } @@ -551,9 +560,12 @@ fn move_next_long_word_end(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - movement::move_next_long_word_end(doc.text().slice(..), range, count) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + movement::move_next_long_word_end(doc.text().slice(..), range, count) + }), ); } @@ -574,12 +586,15 @@ fn extend_next_word_start(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - let text = doc.text().slice(..); - let word = movement::move_next_word_start(text, range, count); - let pos = word.head; - range.put(text, pos, true) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + let text = doc.text().slice(..); + let word = movement::move_next_word_start(text, range, count); + let pos = word.head; + range.put(text, pos, true) + }), ); } @@ -588,12 +603,15 @@ fn extend_prev_word_start(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - let text = doc.text().slice(..); - let word = movement::move_prev_word_start(text, range, count); - let pos = word.head; - range.put(text, pos, true) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + let text = doc.text().slice(..); + let word = movement::move_prev_word_start(text, range, count); + let pos = word.head; + range.put(text, pos, true) + }), ); } @@ -602,12 +620,15 @@ fn extend_next_word_end(cx: &mut Context) { let (view, doc) = current!(cx.editor); doc.set_selection( view.id, - doc.selection(view.id).clone().transform(|range| { - let text = doc.text().slice(..); - let word = movement::move_next_word_end(text, range, count); - let pos = word.head; - range.put(text, pos, true) - }), + doc.selection(view.id) + .clone() + .min_width_1(doc.text().slice(..)) + .transform(|range| { + let text = doc.text().slice(..); + let word = movement::move_next_word_end(text, range, count); + let pos = word.head; + range.put(text, pos, true) + }), ); } -- cgit v1.2.3-70-g09d2