To: vim_dev@googlegroups.com Subject: Patch 8.2.3677 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3677 Problem: After a put the '] mark is on the last byte of a multi-byte character. Solution: Move it to the first byte. (closes #9047) Files: src/register.c, src/testdir/test_put.vim *** ../vim-8.2.3676/src/register.c 2021-11-17 15:51:46.421992164 +0000 --- src/register.c 2021-11-25 19:30:11.855988039 +0000 *************** *** 2004,2009 **** --- 2004,2010 ---- { linenr_T end_lnum = 0; // init for gcc linenr_T start_lnum = lnum; + int first_byte_off = 0; if (VIsual_active) { *************** *** 2065,2070 **** --- 2066,2075 ---- } STRMOVE(ptr, oldp + col); ml_replace(lnum, newp, FALSE); + + // compute the byte offset for the last character + first_byte_off = mb_head_off(newp, ptr - 1); + // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { *************** *** 2080,2089 **** --- 2085,2099 ---- lnum--; } + // put '] at the first byte of the last character curbuf->b_op_end = curwin->w_cursor; + curbuf->b_op_end.col -= first_byte_off; + // For "CTRL-O p" in Insert mode, put cursor after last char if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) ++curwin->w_cursor.col; + else + curwin->w_cursor.col -= first_byte_off; changed_bytes(lnum, col); } else *************** *** 2198,2209 **** changed_lines(curbuf->b_op_start.lnum, 0, curbuf->b_op_start.lnum, nr_lines); ! // put '] mark at last inserted character curbuf->b_op_end.lnum = new_lnum; - // correct length for change in indent col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; if (col > 1) ! curbuf->b_op_end.col = col - 1; else curbuf->b_op_end.col = 0; --- 2208,2221 ---- changed_lines(curbuf->b_op_start.lnum, 0, curbuf->b_op_start.lnum, nr_lines); ! // Put the '] mark on the first byte of the last inserted character. ! // Correct the length for change in indent. curbuf->b_op_end.lnum = new_lnum; col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; if (col > 1) ! curbuf->b_op_end.col = col - 1 ! - mb_head_off(y_array[y_size - 1], ! y_array[y_size - 1] + col - 1); else curbuf->b_op_end.col = 0; *** ../vim-8.2.3676/src/testdir/test_put.vim 2021-11-24 14:59:12.573593141 +0000 --- src/testdir/test_put.vim 2021-11-25 19:26:54.468265979 +0000 *************** *** 197,201 **** --- 197,214 ---- bwipe! endfunc + func Test_multibyte_op_end_mark() + new + call setline(1, 'ั‚ะตัั‚') + normal viwdp + call assert_equal([0, 1, 7, 0], getpos("'>")) + call assert_equal([0, 1, 7, 0], getpos("']")) + + normal Vyp + call assert_equal([0, 1, 2147483647, 0], getpos("'>")) + call assert_equal([0, 2, 7, 0], getpos("']")) + bwipe! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3676/src/version.c 2021-11-25 15:10:45.388754445 +0000 --- src/version.c 2021-11-25 18:52:44.599374597 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3677, /**/ -- A law to reduce crime states: "It is mandatory for a motorist with criminal intentions to stop at the city limits and telephone the chief of police as he is entering the town. [real standing law in Washington, United States of America] /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///