on master help sign in
commands: use chars().count() over .len() on strings
01b1bd1Blaž Hrastnik
helix-term/src/commands.rs+3−3
@@ -1220,7 +1220,7 @@ fn open(cx: &mut Context, open: Open) {
1220 let text = text.repeat(count);
1220 let text = text.repeat(count);
1221
1221
1222 // calculate new selection range
1222 // calculate new selection range
1223− let pos = index + text.len();
1223+ let pos = index + text.chars().count();
1224 ranges.push(Range::new(pos, pos));
1224 ranges.push(Range::new(pos, pos));
1225
1225
1226 (index, index, Some(text.into()))
1226 (index, index, Some(text.into()))
@@ -1811,7 +1811,7 @@ pub mod insert {
1811 text.push('\n');
1811 text.push('\n');
1812 text.push_str(&indent);
1812 text.push_str(&indent);
1813
1813
1814− let head = pos + offs + text.len();
1814+ let head = pos + offs + text.chars().count();
1815
1815
1816 // TODO: range replace or extend
1816 // TODO: range replace or extend
1817 // range.replace(|range| range.is_empty(), head); -> fn extend if cond true, new head pos
1817 // range.replace(|range| range.is_empty(), head); -> fn extend if cond true, new head pos
@@ -1833,7 +1833,7 @@ pub mod insert {
1833 text.push_str(&indent);
1833 text.push_str(&indent);
1834 }
1834 }
1835
1835
1836− offs += text.len();
1836+ offs += text.chars().count();
1837
1837
1838 (pos, pos, Some(text.into()))
1838 (pos, pos, Some(text.into()))
1839 });
1839 });