@@ -3,6 +3,7 @@ use ropey::{iter::Chunks, str_utils::byte_to_char_idx, RopeSlice};
3use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
3use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
4use unicode_width::UnicodeWidthStr;
4use unicode_width::UnicodeWidthStr;
6pub fn grapheme_width(g: &str) -> usize {
7pub fn grapheme_width(g: &str) -> usize {
7 if g.as_bytes()[0] <= 127 {
8 if g.as_bytes()[0] <= 127 {
8 // Fast-path ascii.
9 // Fast-path ascii.
@@ -26,6 +27,7 @@ pub fn grapheme_width(g: &str) -> usize {
29pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
31pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
30 // Bounds check
32 // Bounds check
31 debug_assert!(char_idx <= slice.len_chars());
33 debug_assert!(char_idx <= slice.len_chars());
@@ -71,6 +73,7 @@ pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
71 nth_prev_grapheme_boundary(slice, char_idx, 1)
73 nth_prev_grapheme_boundary(slice, char_idx, 1)
74pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
77pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
75 // Bounds check
78 // Bounds check
76 debug_assert!(char_idx <= slice.len_chars());
79 debug_assert!(char_idx <= slice.len_chars());
@@ -138,12 +141,12 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
138 let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
141 let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
139 gc.provide_context(ctx_chunk, ctx_byte_start);
142 gc.provide_context(ctx_chunk, ctx_byte_start);
141− _ => unreachable!(),
144+ Err(_) => unreachable!(),
146−/// An iterator over the graphemes of a RopeSlice.
149+/// An iterator over the graphemes of a `RopeSlice`.
147#[derive(Clone)]
150#[derive(Clone)]
148pub struct RopeGraphemes<'a> {
151pub struct RopeGraphemes<'a> {
149 text: RopeSlice<'a>,
152 text: RopeSlice<'a>,
@@ -154,6 +157,7 @@ pub struct RopeGraphemes<'a> {
156impl<'a> RopeGraphemes<'a> {
159impl<'a> RopeGraphemes<'a> {
157 pub fn new(slice: RopeSlice) -> RopeGraphemes {
161 pub fn new(slice: RopeSlice) -> RopeGraphemes {
158 let mut chunks = slice.chunks();
162 let mut chunks = slice.chunks();
159 let first_chunk = chunks.next().unwrap_or("");
163 let first_chunk = chunks.next().unwrap_or("");