From 9f7ac7da1e2611fc23fd3f80abbe709c92d9c24a Mon Sep 17 00:00:00 2001 From: Polesznyák Márk Date: Tue, 21 Oct 2025 17:33:58 +0200 Subject: fix: `Selection::text` not accounting for graphemes larger than 1 byte --- src/selection.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/selection.rs') diff --git a/src/selection.rs b/src/selection.rs index 32c8807..b98a113 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -82,22 +82,31 @@ impl Selection { let lines_total = end.line - start.line + 1; for (idx, line) in buffer_lines.iter().enumerate().take(lines_total) { - let text = line.text(); + let text = Value::new(line.text()); let length = text.len(); if idx == 0 { if lines_total == 1 { value.push_str( - &text[start.index.min(length)..end.index.min(length)], + &text + .select( + start.index.min(length), + end.index.min(length), + ) + .to_string(), ); } else { - value.push_str(&dbg!(text)[start.index.min(length)..]); + value.push_str( + &text + .select(start.index.min(length), length) + .to_string(), + ); value.push_str(line.ending().as_str()); } } else if idx == lines_total - 1 { - value.push_str(&text[..end.index.min(length)]); + value.push_str(&text.until(end.index.min(length)).to_string()); } else { - value.push_str(text); + value.push_str(&text.to_string()); value.push_str(line.ending().as_str()); } } -- cgit v1.2.3