From b873fb9897bb5b24a60cca3d9fa69285446a857f Mon Sep 17 00:00:00 2001 From: Kirawi Date: Tue, 8 Jun 2021 00:20:15 -0400 Subject: Fix Unicode (#135) * init * wip * wip * fix unicode break * fix unicode break * Update helix-core/src/transaction.rs Co-authored-by: Benoît Cortier * clippy * fix * add changes * added test * wip * wip * wip * wip * fix * fix view * fix #88 Co-authored-by: Benoît Cortier --- helix-term/src/commands.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0da23fc7..2412e55d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -654,9 +654,10 @@ pub fn split_selection_on_newline(cx: &mut Context) { fn _search(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, extend: bool) { let text = doc.text(); let selection = doc.selection(view.id); - let start = selection.cursor(); + let start = text.char_to_byte(selection.cursor()); // use find_at to find the next match after the cursor, loop around the end + // Careful, `Regex` uses `bytes` as offsets, not character indices! let mat = regex .find_at(contents, start) .or_else(|| regex.find(contents)); @@ -670,7 +671,7 @@ fn _search(doc: &mut Document, view: &mut View, contents: &str, regex: &Regex, e return; } - let head = end; + let head = end - 1; let selection = if extend { selection.clone().push(Range::new(start, head)) @@ -1027,7 +1028,7 @@ pub fn command_mode(cx: &mut Context) { let mut prompt = Prompt::new( ":".to_owned(), |input: &str| { - // we use .this over split_ascii_whitespace() because we care about empty segments + // we use .this over split_whitespace() because we care about empty segments let parts = input.split(' ').collect::>(); // simple heuristic: if there's no just one part, complete command name. @@ -1069,7 +1070,7 @@ pub fn command_mode(cx: &mut Context) { return; } - let parts = input.split_ascii_whitespace().collect::>(); + let parts = input.split_whitespace().collect::>(); if parts.is_empty() { return; } -- cgit v1.2.3-70-g09d2