diff options
author | David Bürgin <676c7473@gmail.com> | 2015-05-09 21:22:50 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-05-26 00:49:05 -0400 |
commit | c6da5033362c76f3641f4871046a40465fe0615a (patch) | |
tree | 942191f9ec8e7868b354c5143812201190fd67f6 /src | |
parent | a7b5ae37a71dae93f86da3003bf267fc4f4490f0 (diff) | |
download | rneovim-c6da5033362c76f3641f4871046a40465fe0615a.tar.gz rneovim-c6da5033362c76f3641f4871046a40465fe0615a.tar.bz2 rneovim-c6da5033362c76f3641f4871046a40465fe0615a.zip |
vim-patch:7.4.579 #2652
Problem: Wrong cursor positioning when 'linebreak' is set and lines wrap.
Solution: (Christian Brabandt)
https://github.com/vim/vim/commit/v7-4-579
See https://groups.google.com/d/msg/vim_dev/Eh3N9L68Ajw/4dB5x1RTQJQJ
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/charset.c | 43 | ||||
-rw-r--r-- | src/nvim/screen.c | 13 | ||||
-rw-r--r-- | src/nvim/version.c | 2 |
3 files changed, 46 insertions, 12 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index da65839353..b93eafbf60 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1049,29 +1049,54 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he added = 0; if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && (col != 0)) { - numberextra = win_col_off(wp); + colnr_T sbrlen = 0; + int numberwidth = win_col_off(wp); + + numberextra = numberwidth; col += numberextra + mb_added; if (col >= (colnr_T)wp->w_width) { col -= wp->w_width; numberextra = wp->w_width - (numberextra - win_col_off2(wp)); - if (numberextra > 0) { + if (col >= numberextra && numberextra > 0) { col %= numberextra; } if (*p_sbr != NUL) { - colnr_T sbrlen = (colnr_T)MB_CHARLEN(p_sbr); - if (col >= sbrlen) + sbrlen = (colnr_T)MB_CHARLEN(p_sbr); + if (col >= sbrlen) { col -= sbrlen; + } } - if (numberextra > 0) { - col = col % numberextra; + if (col >= numberextra && numberextra > 0) { + col %= numberextra; + } else if (col > 0 && numberextra > 0) { + col += numberwidth - win_col_off2(wp); } + + numberwidth -= win_col_off2(wp); } - if ((col == 0) || (col + size > (colnr_T)wp->w_width)) { + if (col == 0 || (col + size + sbrlen > (colnr_T)wp->w_width)) { added = 0; - if (*p_sbr != NUL) - added += vim_strsize(p_sbr); + + if (*p_sbr != NUL) { + if (size + sbrlen + numberwidth > (colnr_T)wp->w_width) { + // Calculate effective window width. + int width = (colnr_T)wp->w_width - sbrlen - numberwidth; + int prev_width = col ? ((colnr_T)wp->w_width - (sbrlen + col)) : 0; + if (width == 0) { + width = (colnr_T)wp->w_width; + } + added += ((size - prev_width) / width) * vim_strsize(p_sbr); + if ((size - prev_width) % width) { + // Wrapped, add another length of 'sbr'. + added += vim_strsize(p_sbr); + } + } else { + added += vim_strsize(p_sbr); + } + } + if (wp->w_p_bri) added += get_breakindent_win(wp, line); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 4442e7bba6..7a6e3c59c0 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2063,6 +2063,7 @@ win_line ( unsigned off; /* offset in ScreenLines/ScreenAttrs */ int c = 0; /* init for GCC */ long vcol = 0; /* virtual column (for tabs) */ + long vcol_sbr = -1; // virtual column after showbreak long vcol_prev = -1; /* "vcol" of previous character */ char_u *line; /* current line */ char_u *ptr; /* current position in "line" */ @@ -2761,6 +2762,7 @@ win_line ( n_extra = (int)STRLEN(p_sbr); char_attr = hl_attr(HLF_AT); need_showbreak = FALSE; + vcol_sbr = vcol + MB_CHARLEN(p_sbr); /* Correct end of highlighted area for 'showbreak', * required when 'linebreak' is also set. */ if (tocol == vcol) @@ -3361,9 +3363,16 @@ win_line ( */ if (c == TAB && (!wp->w_p_list || lcs_tab1)) { int tab_len = 0; - /* tab amount depends on current column */ + long vcol_adjusted = vcol; // removed showbreak length + // Only adjust the tab_len, when at the first column after the + // showbreak value was drawn. + if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) { + vcol_adjusted = vcol - MB_CHARLEN(p_sbr); + } + // tab amount depends on current column tab_len = (int)wp->w_buffer->b_p_ts - - vcol % (int)wp->w_buffer->b_p_ts - 1; + - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; + if (!wp->w_p_lbr || !wp->w_p_list) { n_extra = tab_len; } else { diff --git a/src/nvim/version.c b/src/nvim/version.c index 3a95e9373a..d9bdafbb68 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -221,7 +221,7 @@ static int included_patches[] = { //582, //581 NA 580, - //579, + 579, 578, 577, 576, |