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