Skip to main content

cursor_visual_col

Function cursor_visual_col 

Source
pub fn cursor_visual_col(line: &str, char_col: usize, tab_width: usize) -> usize
Expand description

vim’s curswant for a Normal- or Visual-mode cursor on char_col: the display column the cursor is drawn in. That is a tab’s LAST cell — outside Insert mode vim puts the cursor at the end of a tab, and j off one aims there — and every other character’s first, as char_col_to_visual_col gives (a double-width glyph keeps its leading cell).

§Examples

use hjkl_buffer::cursor_visual_col;

// On the tab of `a\tb` (tab width 4) the cursor stands in cell 3.
assert_eq!(cursor_visual_col("a\tb", 1, 4), 3);
// Any other char: its first cell.
assert_eq!(cursor_visual_col("a\tb", 2, 4), 4);
assert_eq!(cursor_visual_col("ab世界cd", 3, 4), 4);