|
|
@ -1,8 +1,9 @@
|
|
|
|
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
chars::char_is_line_ending,
|
|
|
|
chars::char_is_line_ending,
|
|
|
|
graphemes::{ensure_grapheme_boundary_prev, RopeGraphemes},
|
|
|
|
graphemes::{ensure_grapheme_boundary_prev, grapheme_width, RopeGraphemes},
|
|
|
|
line_ending::line_end_char_index,
|
|
|
|
line_ending::line_end_char_index,
|
|
|
|
unicode::width::UnicodeWidthChar,
|
|
|
|
|
|
|
|
RopeSlice,
|
|
|
|
RopeSlice,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -77,14 +78,17 @@ pub fn visual_coords_at_pos(text: RopeSlice, pos: usize, tab_width: usize) -> Po
|
|
|
|
|
|
|
|
|
|
|
|
let line_start = text.line_to_char(line);
|
|
|
|
let line_start = text.line_to_char(line);
|
|
|
|
let pos = ensure_grapheme_boundary_prev(text, pos);
|
|
|
|
let pos = ensure_grapheme_boundary_prev(text, pos);
|
|
|
|
let col = text
|
|
|
|
|
|
|
|
.slice(line_start..pos)
|
|
|
|
let mut col = 0;
|
|
|
|
.chars()
|
|
|
|
|
|
|
|
.flat_map(|c| match c {
|
|
|
|
for grapheme in RopeGraphemes::new(text.slice(line_start..pos)) {
|
|
|
|
'\t' => Some(tab_width),
|
|
|
|
if grapheme == "\t" {
|
|
|
|
c => UnicodeWidthChar::width(c),
|
|
|
|
col += tab_width;
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
.sum();
|
|
|
|
let grapheme = Cow::from(grapheme);
|
|
|
|
|
|
|
|
col += grapheme_width(&grapheme);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Position::new(line, col)
|
|
|
|
Position::new(line, col)
|
|
|
|
}
|
|
|
|
}
|
|
|
|