aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolesznyák Márk <contact@pml68.dev>2025-10-21 17:33:58 +0200
committerPolesznyák Márk <contact@pml68.dev>2025-10-21 17:33:58 +0200
commit9f7ac7da1e2611fc23fd3f80abbe709c92d9c24a (patch)
tree87afdc88c22e546da71d034fff4a2969c66b355a
parentdocs(README): add some new sections, extend existing ones (diff)
downloadiced_selection-9f7ac7da1e2611fc23fd3f80abbe709c92d9c24a.tar.gz
fix: `Selection::text` not accounting for graphemes larger than 1 byte
-rw-r--r--src/selection.rs19
1 files changed, 14 insertions, 5 deletions
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());
}
}