on master help sign in
commands: use chars().count() over .len() on strings
commit01b1bd15a1536244f9cd9ffd7c29ae9bfca66613 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 7 Jun 2021, 09:26 (5 years ago) parentff8a031
1 file changed+3−3
helix-term/src/commands.rs+3−3
helix-term/src/commands.rs+3−3
@@ -1220,7 +1220,7 @@ fn open(cx: &mut Context, open: Open) {
12201220 let text = text.repeat(count);
12211221
12221222 // calculate new selection range
1223− let pos = index + text.len();
1223+ let pos = index + text.chars().count();
12241224 ranges.push(Range::new(pos, pos));
12251225
12261226 (index, index, Some(text.into()))
@@ -1811,7 +1811,7 @@ pub mod insert {
18111811 text.push('\n');
18121812 text.push_str(&indent);
18131813
1814− let head = pos + offs + text.len();
1814+ let head = pos + offs + text.chars().count();
18151815
18161816 // TODO: range replace or extend
18171817 // range.replace(|range| range.is_empty(), head); -> fn extend if cond true, new head pos
@@ -1833,7 +1833,7 @@ pub mod insert {
18331833 text.push_str(&indent);
18341834 }
18351835
1836− offs += text.len();
1836+ offs += text.chars().count();
18371837
18381838 (pos, pos, Some(text.into()))
18391839 });