comparison src/register.c @ 26292:b79f122c6bd8 v8.2.3677

patch 8.2.3677: after a put the '] mark is on the last byte Commit: https://github.com/vim/vim/commit/4d07253a485819b3a9fd923d263e722ea2109c12 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 25 19:31:15 2021 +0000 patch 8.2.3677: after a put the '] mark is on the last byte 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Nov 2021 20:45:03 +0100
parents f2392648af3e
children ba835881a79e
comparison
equal deleted inserted replaced
26291:f3ace6b2bc84 26292:b79f122c6bd8
2002 // simple case: insert into one line at a time 2002 // simple case: insert into one line at a time
2003 if (y_type == MCHAR && y_size == 1) 2003 if (y_type == MCHAR && y_size == 1)
2004 { 2004 {
2005 linenr_T end_lnum = 0; // init for gcc 2005 linenr_T end_lnum = 0; // init for gcc
2006 linenr_T start_lnum = lnum; 2006 linenr_T start_lnum = lnum;
2007 int first_byte_off = 0;
2007 2008
2008 if (VIsual_active) 2009 if (VIsual_active)
2009 { 2010 {
2010 end_lnum = curbuf->b_visual.vi_end.lnum; 2011 end_lnum = curbuf->b_visual.vi_end.lnum;
2011 if (end_lnum < curbuf->b_visual.vi_start.lnum) 2012 if (end_lnum < curbuf->b_visual.vi_start.lnum)
2063 mch_memmove(ptr, y_array[0], (size_t)yanklen); 2064 mch_memmove(ptr, y_array[0], (size_t)yanklen);
2064 ptr += yanklen; 2065 ptr += yanklen;
2065 } 2066 }
2066 STRMOVE(ptr, oldp + col); 2067 STRMOVE(ptr, oldp + col);
2067 ml_replace(lnum, newp, FALSE); 2068 ml_replace(lnum, newp, FALSE);
2069
2070 // compute the byte offset for the last character
2071 first_byte_off = mb_head_off(newp, ptr - 1);
2072
2068 // Place cursor on last putted char. 2073 // Place cursor on last putted char.
2069 if (lnum == curwin->w_cursor.lnum) 2074 if (lnum == curwin->w_cursor.lnum)
2070 { 2075 {
2071 // make sure curwin->w_virtcol is updated 2076 // make sure curwin->w_virtcol is updated
2072 changed_cline_bef_curs(); 2077 changed_cline_bef_curs();
2078 2083
2079 if (VIsual_active) // reset lnum to the last visual line 2084 if (VIsual_active) // reset lnum to the last visual line
2080 lnum--; 2085 lnum--;
2081 } 2086 }
2082 2087
2088 // put '] at the first byte of the last character
2083 curbuf->b_op_end = curwin->w_cursor; 2089 curbuf->b_op_end = curwin->w_cursor;
2090 curbuf->b_op_end.col -= first_byte_off;
2091
2084 // For "CTRL-O p" in Insert mode, put cursor after last char 2092 // For "CTRL-O p" in Insert mode, put cursor after last char
2085 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) 2093 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND)))
2086 ++curwin->w_cursor.col; 2094 ++curwin->w_cursor.col;
2095 else
2096 curwin->w_cursor.col -= first_byte_off;
2087 changed_bytes(lnum, col); 2097 changed_bytes(lnum, col);
2088 } 2098 }
2089 else 2099 else
2090 { 2100 {
2091 linenr_T new_lnum = new_cursor.lnum; 2101 linenr_T new_lnum = new_cursor.lnum;
2196 curwin->w_cursor.lnum + 1, nr_lines); 2206 curwin->w_cursor.lnum + 1, nr_lines);
2197 else 2207 else
2198 changed_lines(curbuf->b_op_start.lnum, 0, 2208 changed_lines(curbuf->b_op_start.lnum, 0,
2199 curbuf->b_op_start.lnum, nr_lines); 2209 curbuf->b_op_start.lnum, nr_lines);
2200 2210
2201 // put '] mark at last inserted character 2211 // Put the '] mark on the first byte of the last inserted character.
2212 // Correct the length for change in indent.
2202 curbuf->b_op_end.lnum = new_lnum; 2213 curbuf->b_op_end.lnum = new_lnum;
2203 // correct length for change in indent
2204 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; 2214 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff;
2205 if (col > 1) 2215 if (col > 1)
2206 curbuf->b_op_end.col = col - 1; 2216 curbuf->b_op_end.col = col - 1
2217 - mb_head_off(y_array[y_size - 1],
2218 y_array[y_size - 1] + col - 1);
2207 else 2219 else
2208 curbuf->b_op_end.col = 0; 2220 curbuf->b_op_end.col = 0;
2209 2221
2210 if (flags & PUT_CURSLINE) 2222 if (flags & PUT_CURSLINE)
2211 { 2223 {