To: vim_dev@googlegroups.com Subject: Patch 8.1.0125 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0125 Problem: Virtual edit replace with multi-byte fails at end of line. (Lukas Werling) Solution: use ins_char() to add the character. (Christian Brabandt, closes #3114) Rename PCHAR() to PBYTE() to avoid mistakes like this. Files: src/ops.c, src/testdir/test_virtualedit.vim, src/macros.h *** ../vim-8.1.0124/src/ops.c 2018-06-27 20:49:40.567862384 +0200 --- src/ops.c 2018-06-28 19:20:39.671555865 +0200 *************** *** 2146,2151 **** --- 2146,2170 ---- #endif #if defined(FEAT_VISUALEXTRA) || defined(PROTO) + + # ifdef FEAT_MBYTE + /* + * Replace the character under the cursor with "c". + * This takes care of multi-byte characters. + */ + static void + replace_character(int c) + { + int n = State; + + State = REPLACE; + ins_char(c); + State = n; + /* Backup to the replaced character. */ + dec_cursor(); + } + + # endif /* * Replace a whole area with one character. */ *************** *** 2331,2342 **** * with a multi-byte and the other way around. */ if (curwin->w_cursor.lnum == oap->end.lnum) oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); ! n = State; ! State = REPLACE; ! ins_char(c); ! State = n; ! /* Backup to the replaced character. */ ! dec_cursor(); } else #endif --- 2350,2356 ---- * with a multi-byte and the other way around. */ if (curwin->w_cursor.lnum == oap->end.lnum) oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); ! replace_character(c); } else #endif *************** *** 2358,2364 **** getvpos(&oap->end, end_vcol); } #endif ! PCHAR(curwin->w_cursor, c); } } #ifdef FEAT_VIRTUALEDIT --- 2372,2378 ---- getvpos(&oap->end, end_vcol); } #endif ! PBYTE(curwin->w_cursor, c); } } #ifdef FEAT_VIRTUALEDIT *************** *** 2377,2385 **** curwin->w_cursor.col -= (virtcols + 1); for (; virtcols >= 0; virtcols--) { ! PCHAR(curwin->w_cursor, c); ! if (inc(&curwin->w_cursor) == -1) ! break; } } #endif --- 2391,2404 ---- curwin->w_cursor.col -= (virtcols + 1); for (; virtcols >= 0; virtcols--) { ! #ifdef FEAT_MBYTE ! if ((*mb_char2len)(c) > 1) ! replace_character(c); ! else ! #endif ! PBYTE(curwin->w_cursor, c); ! if (inc(&curwin->w_cursor) == -1) ! break; } } #endif *************** *** 2619,2625 **** } else #endif ! PCHAR(*pos, nc); return TRUE; } return FALSE; --- 2638,2644 ---- } else #endif ! PBYTE(*pos, nc); return TRUE; } return FALSE; *** ../vim-8.1.0124/src/testdir/test_virtualedit.vim 2018-04-25 21:58:46.000000000 +0200 --- src/testdir/test_virtualedit.vim 2018-06-28 19:12:57.486074037 +0200 *************** *** 42,47 **** --- 42,63 ---- set virtualedit= endfunc + func Test_replace_end_of_line() + new + set virtualedit=all + call setline(1, range(20)) + exe "normal! gg2jv10lr-" + call assert_equal(["1", "-----------", "3"], getline(2,4)) + if has('multi_byte') + call setline(1, range(20)) + exe "normal! gg2jv10lr\hh" + call assert_equal(["1", "───────────", "3"], getline(2,4)) + endif + + bwipe! + set virtualedit= + endfunc + func Test_edit_CTRL_G() new set virtualedit=insert *** ../vim-8.1.0124/src/macros.h 2018-04-10 18:37:19.000000000 +0200 --- src/macros.h 2018-06-28 19:15:50.801135759 +0200 *************** *** 14,22 **** */ /* ! * PCHAR(lp, c) - put character 'c' at position 'lp' */ ! #define PCHAR(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c)) /* * Position comparisons --- 14,22 ---- */ /* ! * PBYTE(lp, c) - put byte 'c' at position 'lp' */ ! #define PBYTE(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c)) /* * Position comparisons *** ../vim-8.1.0124/src/version.c 2018-06-28 15:50:23.178568297 +0200 --- src/version.c 2018-06-28 19:11:53.922415636 +0200 *************** *** 791,792 **** --- 791,794 ---- { /* Add new patch number below this line */ + /**/ + 125, /**/ -- The coffee just wasn't strong enough to defend itself -- Tom Waits /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///