diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-01-25 16:21:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-25 16:21:09 -0800 |
commit | a75c289eb8133b418ea0f7bca99f38e1e9e1eca0 (patch) | |
tree | 66def07f828119b316fa8323de795212d691cc16 | |
parent | 71ee46accfd235bad2b8460065100b31bb2d8165 (diff) | |
parent | 94ad6652f11e1d6791292d0a2bf2d777ddeefbcc (diff) | |
download | rneovim-a75c289eb8133b418ea0f7bca99f38e1e9e1eca0.tar.gz rneovim-a75c289eb8133b418ea0f7bca99f38e1e9e1eca0.tar.bz2 rneovim-a75c289eb8133b418ea0f7bca99f38e1e9e1eca0.zip |
Merge #11750 from janlazo/vim-8.2.0146
vim-patch:8.1.2245,8.2.{146,147}
-rw-r--r-- | src/nvim/memline.c | 5 | ||||
-rw-r--r-- | src/nvim/normal.c | 176 | ||||
-rw-r--r-- | src/nvim/ops.c | 43 | ||||
-rw-r--r-- | src/nvim/screen.c | 35 | ||||
-rw-r--r-- | src/nvim/testdir/test_breakindent.vim | 67 | ||||
-rw-r--r-- | src/nvim/testdir/test_listlbr.vim | 31 |
6 files changed, 204 insertions, 153 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c index e5ba17a0a7..922b684120 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1802,9 +1802,10 @@ char_u *ml_get(linenr_T lnum) /* * Return pointer to position "pos". */ -char_u *ml_get_pos(pos_T *pos) +char_u *ml_get_pos(const pos_T *pos) + FUNC_ATTR_NONNULL_ALL { - return ml_get_buf(curbuf, pos->lnum, FALSE) + pos->col; + return ml_get_buf(curbuf, pos->lnum, false) + pos->col; } /* diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 3aff3cef84..dac4c8f527 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -760,7 +760,7 @@ static void normal_get_additional_char(NormalState *s) // because if it's put back with vungetc() it's too late to apply // mapping. no_mapping--; - while (enc_utf8 && lang && (s->c = vpeekc()) > 0 + while (lang && (s->c = vpeekc()) > 0 && (s->c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) { s->c = plain_vgetc(); if (!utf_iscomposing(s->c)) { @@ -1711,13 +1711,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } } - /* Include the trailing byte of a multi-byte char. */ - if (has_mbyte && oap->inclusive) { - int l; - - l = (*mb_ptr2len)(ml_get_pos(&oap->end)); - if (l > 1) + // Include the trailing byte of a multi-byte char. + if (oap->inclusive) { + const int l = utfc_ptr2len(ml_get_pos(&oap->end)); + if (l > 1) { oap->end.col += l - 1; + } } curwin->w_set_curswant = true; @@ -1846,10 +1845,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) restart_edit = 0; // Restore linebreak, so that when the user edits it looks as before. - if (curwin->w_p_lbr != lbr_saved) { - curwin->w_p_lbr = lbr_saved; - get_op_vcol(oap, redo_VIsual_mode, false); - } + curwin->w_p_lbr = lbr_saved; // Reset finish_op now, don't want it set inside edit(). finish_op = false; @@ -1935,10 +1931,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) restart_edit = 0; // Restore linebreak, so that when the user edits it looks as before. - if (curwin->w_p_lbr != lbr_saved) { - curwin->w_p_lbr = lbr_saved; - get_op_vcol(oap, redo_VIsual_mode, false); - } + curwin->w_p_lbr = lbr_saved; op_insert(oap, cap->count1); @@ -1964,10 +1957,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } else { // Restore linebreak, so that when the user edits it looks as before. - if (curwin->w_p_lbr != lbr_saved) { - curwin->w_p_lbr = lbr_saved; - get_op_vcol(oap, redo_VIsual_mode, false); - } + curwin->w_p_lbr = lbr_saved; op_replace(oap, cap->nchar); } @@ -2906,17 +2896,17 @@ static void find_end_of_word(pos_T *pos) */ static int get_mouse_class(char_u *p) { - int c; - - if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) + if (MB_BYTE2LEN(p[0]) > 1) { return mb_get_class(p); + } - c = *p; - if (c == ' ' || c == '\t') + const int c = *p; + if (c == ' ' || c == '\t') { return 0; - - if (vim_iswordc(c)) + } + if (vim_iswordc(c)) { return 2; + } /* * There are a few special cases where we want certain combinations of @@ -4916,10 +4906,9 @@ static void nv_ident(cmdarg_T *cap) *p++ = '\\'; /* When current byte is a part of multibyte character, copy all * bytes of that character. */ - if (has_mbyte) { - size_t len = (size_t)((*mb_ptr2len)(ptr) - 1); - for (size_t i = 0; i < len && n > 0; ++i, --n) - *p++ = *ptr++; + const size_t len = (size_t)(utfc_ptr2len(ptr) - 1); + for (size_t i = 0; i < len && n > 0; i++, n--) { + *p++ = *ptr++; } *p++ = *ptr++; } @@ -4930,11 +4919,11 @@ static void nv_ident(cmdarg_T *cap) * Execute the command. */ if (cmdchar == '*' || cmdchar == '#') { - if (!g_cmd && ( - has_mbyte ? vim_iswordp(mb_prevptr(get_cursor_line_ptr(), ptr)) : - vim_iswordc(ptr[-1]))) + if (!g_cmd + && vim_iswordp(mb_prevptr(get_cursor_line_ptr(), ptr))) { STRCAT(buf, "\\>"); - /* put pattern in search history */ + } + // put pattern in search history init_history(); add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL); (void)normal_search(cap, cmdchar == '*' ? '/' : '?', (char_u *)buf, 0, @@ -4977,9 +4966,8 @@ get_visual_text ( *pp = ml_get_pos(&VIsual); *lenp = (size_t)curwin->w_cursor.col - (size_t)VIsual.col + 1; } - if (has_mbyte) - /* Correct the length to include the whole last character. */ - *lenp += (size_t)((*mb_ptr2len)(*pp + (*lenp - 1)) - 1); + // Correct the length to include the whole last character. + *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); } reset_VIsual_and_resel(); return true; @@ -5197,11 +5185,7 @@ static void nv_left(cmdarg_T *cap) char_u *cp = get_cursor_pos_ptr(); if (*cp != NUL) { - if (has_mbyte) { - curwin->w_cursor.col += (*mb_ptr2len)(cp); - } else { - curwin->w_cursor.col++; - } + curwin->w_cursor.col += utfc_ptr2len(cp); } cap->retval |= CA_NO_ADJ_OP_END; } @@ -5859,7 +5843,6 @@ static void nv_replace(cmdarg_T *cap) { char_u *ptr; int had_ctrl_v; - long n; if (checkclearop(cap->oap)) return; @@ -5913,7 +5896,7 @@ static void nv_replace(cmdarg_T *cap) /* Abort if not enough characters to replace. */ ptr = get_cursor_pos_ptr(); if (STRLEN(ptr) < (unsigned)cap->count1 - || (has_mbyte && mb_charlen(ptr) < cap->count1) + || (mb_charlen(ptr) < cap->count1) ) { clearopbeep(cap->oap); return; @@ -5955,71 +5938,44 @@ static void nv_replace(cmdarg_T *cap) NUL, 'r', NUL, had_ctrl_v, cap->nchar); curbuf->b_op_start = curwin->w_cursor; - if (has_mbyte) { - int old_State = State; - - if (cap->ncharC1 != 0) - AppendCharToRedobuff(cap->ncharC1); - if (cap->ncharC2 != 0) - AppendCharToRedobuff(cap->ncharC2); - - /* This is slow, but it handles replacing a single-byte with a - * multi-byte and the other way around. Also handles adding - * composing characters for utf-8. */ - for (n = cap->count1; n > 0; --n) { - State = REPLACE; - if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { - int c = ins_copychar(curwin->w_cursor.lnum - + (cap->nchar == Ctrl_Y ? -1 : 1)); - if (c != NUL) - ins_char(c); - else - /* will be decremented further down */ - ++curwin->w_cursor.col; - } else - ins_char(cap->nchar); - State = old_State; - if (cap->ncharC1 != 0) - ins_char(cap->ncharC1); - if (cap->ncharC2 != 0) - ins_char(cap->ncharC2); - } - } else { - /* - * Replace the characters within one line. - */ - for (n = cap->count1; n > 0; --n) { - /* - * Get ptr again, because u_save and/or showmatch() will have - * released the line. At the same time we let know that the - * line will be changed. - */ - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); - if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { - int c = ins_copychar(curwin->w_cursor.lnum - + (cap->nchar == Ctrl_Y ? -1 : 1)); - if (c != NUL) { - assert(c >= 0 && c <= UCHAR_MAX); - ptr[curwin->w_cursor.col] = (char_u)c; - } + const int old_State = State; + + if (cap->ncharC1 != 0) { + AppendCharToRedobuff(cap->ncharC1); + } + if (cap->ncharC2 != 0) { + AppendCharToRedobuff(cap->ncharC2); + } + + // This is slow, but it handles replacing a single-byte with a + // multi-byte and the other way around. Also handles adding + // composing characters for utf-8. + for (long n = cap->count1; n > 0; n--) { + State = REPLACE; + if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { + int c = ins_copychar(curwin->w_cursor.lnum + + (cap->nchar == Ctrl_Y ? -1 : 1)); + if (c != NUL) { + ins_char(c); } else { - assert(cap->nchar >= 0 && cap->nchar <= UCHAR_MAX); - ptr[curwin->w_cursor.col] = (char_u)cap->nchar; + // will be decremented further down + curwin->w_cursor.col++; } - if (p_sm && msg_silent == 0) - showmatch(cap->nchar); - ++curwin->w_cursor.col; + } else { + ins_char(cap->nchar); + } + State = old_State; + if (cap->ncharC1 != 0) { + ins_char(cap->ncharC1); + } + if (cap->ncharC2 != 0) { + ins_char(cap->ncharC2); } - - /* mark the buffer as changed and prepare for displaying */ - changed_bytes(curwin->w_cursor.lnum, - (colnr_T)(curwin->w_cursor.col - cap->count1)); } --curwin->w_cursor.col; /* cursor on the last replaced char */ /* if the character on the left of the current cursor is a multi-byte * character, move two characters left */ - if (has_mbyte) - mb_adjust_cursor(); + mb_adjust_cursor(); curbuf->b_op_end = curwin->w_cursor; curwin->w_set_curswant = true; set_last_insert(cap->nchar); @@ -7365,10 +7321,9 @@ static void adjust_cursor(oparg_T *oap) && (!VIsual_active || *p_sel == 'o') && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 ) { - --curwin->w_cursor.col; - /* prevent cursor from moving on the trail byte */ - if (has_mbyte) - mb_adjust_cursor(); + curwin->w_cursor.col--; + // prevent cursor from moving on the trail byte + mb_adjust_cursor(); oap->inclusive = true; } } @@ -7395,10 +7350,7 @@ static void adjust_for_sel(cmdarg_T *cap) { if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) { - if (has_mbyte) - inc_cursor(); - else - ++curwin->w_cursor.col; + inc_cursor(); cap->oap->inclusive = false; } } @@ -7988,9 +7940,7 @@ static void get_op_vcol( oap->motion_type = kMTBlockWise; // prevent from moving onto a trail byte - if (has_mbyte) { - mark_mb_adjustpos(curwin->w_buffer, &oap->end); - } + mark_mb_adjustpos(curwin->w_buffer, &oap->end); getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); if (!redo_VIsual_busy) { diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 641323ae5e..db5c98ed78 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -357,15 +357,11 @@ static void shift_block(oparg_T *oap, int amount) colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; char_u * old_textstart = bd.textstart; if (bd.startspaces) { - if (has_mbyte) { - if ((*mb_ptr2len)(bd.textstart) == 1) { - bd.textstart++; - } else { - ws_vcol = 0; - bd.startspaces = 0; - } - } else { + if (utfc_ptr2len(bd.textstart) == 1) { bd.textstart++; + } else { + ws_vcol = 0; + bd.startspaces = 0; } } for (; ascii_iswhite(*bd.textstart); ) { @@ -1215,9 +1211,7 @@ static void stuffescaped(const char *arg, int literally) /* stuff a single special character */ if (*arg != NUL) { - const int c = (has_mbyte - ? mb_cptr2char_adv((const char_u **)&arg) - : (uint8_t)(*arg++)); + const int c = mb_cptr2char_adv((const char_u **)&arg); if (literally && ((c < ' ' && c != TAB) || c == DEL)) { stuffcharReadbuff(Ctrl_V); } @@ -1389,8 +1383,7 @@ int op_delete(oparg_T *oap) return FAIL; } - if (has_mbyte) - mb_adjust_opend(oap); + mb_adjust_opend(oap); /* * Imitate the strange Vi behaviour: If the delete spans more than one @@ -1736,8 +1729,7 @@ int op_replace(oparg_T *oap, int c) c = NL; } - if (has_mbyte) - mb_adjust_opend(oap); + mb_adjust_opend(oap); if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) @@ -2012,17 +2004,16 @@ void op_tilde(oparg_T *oap) * Returns TRUE if some character was changed. */ static int swapchars(int op_type, pos_T *pos, int length) + FUNC_ATTR_NONNULL_ALL { - int todo; int did_change = 0; - for (todo = length; todo > 0; --todo) { - if (has_mbyte) { - int len = (*mb_ptr2len)(ml_get_pos(pos)); + for (int todo = length; todo > 0; todo--) { + const int len = utfc_ptr2len(ml_get_pos(pos)); - /* we're counting bytes, not characters */ - if (len > 0) - todo -= len - 1; + // we're counting bytes, not characters + if (len > 0) { + todo -= len - 1; } did_change |= swapchar(op_type, pos); if (inc(pos) == -1) /* at end of file */ @@ -3052,7 +3043,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); // move to start of next multi-byte character - curwin->w_cursor.col += (*mb_ptr2len)(get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); col++; } else { getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); @@ -3615,7 +3606,7 @@ dis_msg( while (*p != NUL && !(*p == ESC && skip_esc && *(p + 1) == NUL) && (n -= ptr2cells(p)) >= 0) { - if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { + if ((l = utfc_ptr2len(p)) > 1) { msg_outtrans_len(p, l); p += l; } else @@ -4414,7 +4405,10 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, char_u *line; char_u *prev_pstart; char_u *prev_pend; + const int lbr_saved = curwin->w_p_lbr; + // Avoid a problem with unwanted linebreaks in block mode. + curwin->w_p_lbr = false; bdp->startspaces = 0; bdp->endspaces = 0; bdp->textlen = 0; @@ -4514,6 +4508,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, } bdp->textcol = (colnr_T) (pstart - line); bdp->textstart = pstart; + curwin->w_p_lbr = lbr_saved; } /// Handle the add/subtract operator. diff --git a/src/nvim/screen.c b/src/nvim/screen.c index a451451726..ae38f657cd 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2243,7 +2243,7 @@ win_line ( int change_start = MAXCOL; // first col of changed area int change_end = -1; // last col of changed area colnr_T trailcol = MAXCOL; // start of trailing spaces - int need_showbreak = false; // overlong line, skip first x chars + bool need_showbreak = false; // overlong line, skip first x chars int line_attr = 0; // attribute for the whole line int line_attr_lowprio = 0; // low-priority attribute for the line matchitem_T *cur; // points to the match list @@ -2654,11 +2654,12 @@ win_line ( else if (fromcol >= 0 && fromcol < vcol) fromcol = vcol; - /* When w_skipcol is non-zero, first line needs 'showbreak' */ - if (wp->w_p_wrap) - need_showbreak = TRUE; - /* When spell checking a word we need to figure out the start of the - * word and if it's badly spelled or not. */ + // When w_skipcol is non-zero, first line needs 'showbreak' + if (wp->w_p_wrap) { + need_showbreak = true; + } + // When spell checking a word we need to figure out the start of the + // word and if it's badly spelled or not. if (has_spell) { size_t len; colnr_T linecol = (colnr_T)(ptr - line); @@ -2975,11 +2976,17 @@ win_line ( } p_extra = NULL; c_extra = ' '; - n_extra = get_breakindent_win(wp, ml_get_buf(wp->w_buffer, lnum, FALSE)); - /* Correct end of highlighted area for 'breakindent', - required wen 'linebreak' is also set. */ - if (tocol == vcol) + c_final = NUL; + n_extra = + get_breakindent_win(wp, ml_get_buf(wp->w_buffer, lnum, false)); + if (wp->w_skipcol > 0 && wp->w_p_wrap) { + need_showbreak = false; + } + // Correct end of highlighted area for 'breakindent', + // required wen 'linebreak' is also set. + if (tocol == vcol) { tocol += n_extra; + } } } @@ -3008,7 +3015,9 @@ win_line ( c_final = NUL; n_extra = (int)STRLEN(p_sbr); char_attr = win_hl_attr(wp, HLF_AT); - need_showbreak = false; + if (wp->w_skipcol == 0 || !wp->w_p_wrap) { + need_showbreak = false; + } vcol_sbr = vcol + MB_CHARLEN(p_sbr); /* Correct end of highlighted area for 'showbreak', * required when 'linebreak' is also set. */ @@ -3285,9 +3294,7 @@ win_line ( } else { int c0; - if (p_extra_free != NULL) { - XFREE_CLEAR(p_extra_free); - } + XFREE_CLEAR(p_extra_free); // Get a character from the line itself. c0 = c = *ptr; diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 4b34420cab..6d88f1dc5a 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -296,3 +296,70 @@ function Test_breakindent16() call s:compare_lines(expect, lines) call s:close_windows() endfunction + +func Test_breakindent17_vartabs() + if !has("vartabs") + return + endif + let s:input = "" + call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++') + call setline(1, "\t" . repeat('a', 63)) + vert resize 30 + norm! 1gg$ + redraw! + let lines = s:screen_lines(1, 30) + let expect = [ + \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa", + \ " +++aaaaaaaaaaaaaaaaaaaaaaa", + \ " +++aaaaaaaaaaaaaa ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set breakindent& list& listchars& showbreak&') +endfunc + +func Test_breakindent18_vartabs() + if !has("vartabs") + return + endif + let s:input = "" + call s:test_windows('setl breakindent list listchars=tab:<->') + call setline(1, "\t" . repeat('a', 63)) + vert resize 30 + norm! 1gg$ + redraw! + let lines = s:screen_lines(1, 30) + let expect = [ + \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa", + \ " aaaaaaaaaaaaaaaaaaaaaaaaaa", + \ " aaaaaaaaaaa ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set breakindent& list& listchars&') +endfunc + +func Test_breakindent19_sbr_nextpage() + let s:input = "" + call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>') + call setline(1, repeat('a', 200)) + norm! 1gg + redraw! + let lines = s:screen_lines(1, 20) + let expect = [ + \ "aaaaaaaaaaaaaaaaaaaa", + \ "> aaaaaaaaaaaaaaaaaa", + \ "> aaaaaaaaaaaaaaaaaa", + \ ] + call s:compare_lines(expect, lines) + " Scroll down one screen line + setl scrolloff=5 + norm! 5gj + redraw! + let lines = s:screen_lines(1, 20) + let expect = [ + \ "> aaaaaaaaaaaaaaaaaa", + \ "> aaaaaaaaaaaaaaaaaa", + \ "> aaaaaaaaaaaaaaaaaa", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set breakindent& briopt& sbr&') +endfunc diff --git a/src/nvim/testdir/test_listlbr.vim b/src/nvim/testdir/test_listlbr.vim index d28dbc444c..cdc5e4cc7c 100644 --- a/src/nvim/testdir/test_listlbr.vim +++ b/src/nvim/testdir/test_listlbr.vim @@ -103,6 +103,37 @@ func Test_linebreak_with_conceal() call s:close_windows() endfunc +func Test_linebreak_with_visual_operations() + call s:test_windows() + let line = '1234567890 2234567890 3234567890' + call setline(1, line) + + " yank + exec "norm! ^w\<C-V>ey" + call assert_equal('2234567890', @@) + exec "norm! w\<C-V>ey" + call assert_equal('3234567890', @@) + + " increment / decrement + exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>" + call assert_equal('1234567890 3234567890 2234567890', getline(1)) + + " replace + exec "norm! ^w\<C-V>3lraw\<C-V>3lrb" + call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1)) + + " tilde + exec "norm! ^w\<C-V>2l~w\<C-V>2l~" + call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1)) + + " delete and insert + exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>" + call assert_equal('1234567890 2345567890 3456567890', getline(1)) + call assert_equal('BBBb', @@) + + call s:close_windows() +endfunc + func Test_virtual_block() call s:test_windows('setl sbr=+') call setline(1, [ |