From 5d14f56fa9822b18107a5a5efac98dfe9d08f8ce Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 3 Mar 2022 17:41:39 +0900 Subject: Reuse visual_coords_at_pos function in view --- helix-view/src/view.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'helix-view') diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 6bc9435c..58a9b602 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -204,19 +204,9 @@ impl View { return None; } - let line_start = text.line_to_char(line); - let line_slice = text.slice(line_start..pos); - let mut col = 0; let tab_width = doc.tab_width(); - - for grapheme in RopeGraphemes::new(line_slice) { - if grapheme == "\t" { - col += tab_width; - } else { - let grapheme = Cow::from(grapheme); - col += grapheme_width(&grapheme); - } - } + // TODO: visual_coords_at_pos also does char_to_line which we ignore, can we reuse the call? + let Position { col, .. } = visual_coords_at_pos(text, pos, tab_width); // It is possible for underflow to occur if the buffer length is larger than the terminal width. let row = line.saturating_sub(self.offset.row); -- cgit v1.2.3-70-g09d2