@@ -243,18 +243,29 @@ impl View {
243 let current_line = text.line(line_number);
243 let current_line = text.line(line_number);
245 let target = (column - inner.x) as usize + self.offset.col;
245 let target = (column - inner.x) as usize + self.offset.col;
246− let mut selected = 0;
246+ let mut col = 0;
248+ // TODO: extract this part as pos_at_visual_coords
248 for grapheme in RopeGraphemes::new(current_line) {
249 for grapheme in RopeGraphemes::new(current_line) {
249− if selected >= target {
250+ if col >= target {
252− if grapheme == "\t" {
254+ let width = if grapheme == "\t" {
253− selected += tab_width;
255+ tab_width - (col % tab_width)
255− let width = grapheme_width(&Cow::from(grapheme));
257+ let grapheme = Cow::from(grapheme);
256− selected += width;
258+ grapheme_width(&grapheme)
261+ // If pos is in the middle of a wider grapheme (tab for example)
262+ // return the starting offset.
263+ if col + width >= target {
268+ // TODO: use byte pos that converts back to char pos?
258 pos += grapheme.chars().count();
269 pos += grapheme.chars().count();