diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-03-25 13:22:45 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:40 +0300 |
commit | 4c26077f30571a69d93b05447e6f765e15bf46e2 (patch) | |
tree | a9a2ece239188d5e606da78d29da463924886d2e /ui/src/terminal/text_editing.rs | |
parent | 9522508a924955768b13cdd996cd52a869a45105 (diff) |
ui: word break with grapheme length, not bytes
#69 East characters are not working.
Diffstat (limited to 'ui/src/terminal/text_editing.rs')
-rw-r--r-- | ui/src/terminal/text_editing.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ui/src/terminal/text_editing.rs b/ui/src/terminal/text_editing.rs index 326ba1aa..6ce24fe2 100644 --- a/ui/src/terminal/text_editing.rs +++ b/ui/src/terminal/text_editing.rs @@ -22,7 +22,7 @@ impl UText { } let (first, _) = self.content.split_at(cursor_pos); - self.grapheme_cursor_pos = split_graphemes(first).len(); + self.grapheme_cursor_pos = first.split_graphemes().len(); self.cursor_pos = cursor_pos; } @@ -34,7 +34,7 @@ impl UText { self.content } pub fn grapheme_len(&self) -> usize { - split_graphemes(&self.content).len() + self.content.split_graphemes().len() } pub fn cursor_inc(&mut self) { @@ -42,8 +42,8 @@ impl UText { return; } - let (_, right) = std::dbg!(self.content.split_at(self.cursor_pos)); - if let Some((_, graph)) = std::dbg!(next_grapheme(right)) { + let (_, right) = self.content.split_at(self.cursor_pos); + if let Some((_, graph)) = right.next_grapheme() { self.cursor_pos += graph.len(); self.grapheme_cursor_pos += 1; } @@ -52,8 +52,8 @@ impl UText { if self.cursor_pos == 0 { return; } - let (left, _) = std::dbg!(self.content.split_at(self.cursor_pos)); - if let Some((_, graph)) = std::dbg!(last_grapheme(left)) { + let (left, _) = self.content.split_at(self.cursor_pos); + if let Some((_, graph)) = left.last_grapheme() { self.cursor_pos -= graph.len(); self.grapheme_cursor_pos -= 1; } @@ -116,7 +116,7 @@ impl UText { * left = xxxxxx....xxgg; * right = xxx; */ - if let Some((offset, graph)) = std::dbg!(last_grapheme(left)) { + if let Some((offset, graph)) = left.last_grapheme() { (offset, graph.len()) } else { return; |