From 6af24b2457752c0d36aaf9f29f03d39afd09937f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 09:39:57 +0200 Subject: Merging upstream version 2:9.1.0199. Signed-off-by: Daniel Baumann --- src/register.c | 91 +++++++++------------------------------------------------- 1 file changed, 14 insertions(+), 77 deletions(-) (limited to 'src/register.c') diff --git a/src/register.c b/src/register.c index f381e30..47ed218 100644 --- a/src/register.c +++ b/src/register.c @@ -832,8 +832,9 @@ insert_reg( if ((State & REPLACE_FLAG) != 0) { pos_T curpos; - u_save_cursor(); - del_bytes((long)STRLEN(y_current->y_array[0]), TRUE, FALSE); + if (u_save_cursor() == FAIL) + return FAIL; + del_chars((long)mb_charlen(y_current->y_array[0]), TRUE); curpos = curwin->w_cursor; if (oneright() == FAIL) // hit end of line, need to put forward (after the current position) @@ -1147,7 +1148,6 @@ op_yank(oparg_T *oap, int deleting, int mess) int yanktype = oap->motion_type; long yanklines = oap->line_count; linenr_T yankendlnum = oap->end.lnum; - char_u *p; char_u *pnew; struct block_def bd; #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) @@ -1239,70 +1239,7 @@ op_yank(oparg_T *oap, int deleting, int mess) case MCHAR: { - colnr_T startcol = 0, endcol = MAXCOL; - int is_oneChar = FALSE; - colnr_T cs, ce; - - p = ml_get(lnum); - bd.startspaces = 0; - bd.endspaces = 0; - - if (lnum == oap->start.lnum) - { - startcol = oap->start.col; - if (virtual_op) - { - getvcol(curwin, &oap->start, &cs, NULL, &ce); - if (ce != cs && oap->start.coladd > 0) - { - // Part of a tab selected -- but don't - // double-count it. - bd.startspaces = (ce - cs + 1) - - oap->start.coladd; - if (bd.startspaces < 0) - bd.startspaces = 0; - startcol++; - } - } - } - - if (lnum == oap->end.lnum) - { - endcol = oap->end.col; - if (virtual_op) - { - getvcol(curwin, &oap->end, &cs, NULL, &ce); - if (p[endcol] == NUL || (cs + oap->end.coladd < ce - // Don't add space for double-wide - // char; endcol will be on last byte - // of multi-byte char. - && (*mb_head_off)(p, p + endcol) == 0)) - { - if (oap->start.lnum == oap->end.lnum - && oap->start.col == oap->end.col) - { - // Special case: inside a single char - is_oneChar = TRUE; - bd.startspaces = oap->end.coladd - - oap->start.coladd + oap->inclusive; - endcol = startcol; - } - else - { - bd.endspaces = oap->end.coladd - + oap->inclusive; - endcol -= oap->inclusive; - } - } - } - } - if (endcol == MAXCOL) - endcol = (colnr_T)STRLEN(p); - if (startcol > endcol || is_oneChar) - bd.textlen = 0; - else - bd.textlen = endcol - startcol + oap->inclusive; - bd.textstart = p + startcol; + charwise_block_prep(oap->start, oap->end, &bd, lnum, oap->inclusive); if (yank_copy_line(&bd, y_idx, FALSE) == FAIL) goto fail; break; @@ -1856,7 +1793,7 @@ do_put( } // get the old line and advance to the position to insert at oldp = ml_get_curline(); - oldlen = (int)STRLEN(oldp); + oldlen = ml_get_curline_len(); init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp); @@ -1902,10 +1839,10 @@ do_put( spaces = y_width + 1; init_chartabsize_arg(&cts, curwin, 0, 0, y_array[i], y_array[i]); - for (j = 0; j < yanklen; j++) + + while (*cts.cts_ptr != NUL) { - spaces -= lbr_chartabsize(&cts); - ++cts.cts_ptr; + spaces -= lbr_chartabsize_adv(&cts); cts.cts_vcol = 0; } clear_chartabsize_arg(&cts); @@ -1987,7 +1924,7 @@ do_put( curwin->w_cursor.col++; // in Insert mode we might be after the NUL, correct for that - len = (colnr_T)STRLEN(ml_get_curline()); + len = ml_get_curline_len(); if (curwin->w_cursor.col > len) curwin->w_cursor.col = len; } @@ -2071,7 +2008,7 @@ do_put( totlen = count * yanklen; do { oldp = ml_get(lnum); - oldlen = (int)STRLEN(oldp); + oldlen = ml_get_len(lnum); if (lnum > start_lnum) { pos_T pos; @@ -2151,7 +2088,7 @@ do_put( lnum = new_cursor.lnum; ptr = ml_get(lnum) + col; totlen = (int)STRLEN(y_array[y_size - 1]); - newp = alloc(STRLEN(ptr) + totlen + 1); + newp = alloc(ml_get_len(lnum) - col + totlen + 1); if (newp == NULL) goto error; STRCPY(newp, y_array[y_size - 1]); @@ -2192,7 +2129,7 @@ do_put( curwin->w_cursor.lnum = lnum; ptr = ml_get(lnum); if (cnt == count && i == y_size - 1) - lendiff = (int)STRLEN(ptr); + lendiff = ml_get_len(lnum); if (*ptr == '#' && preprocs_left()) indent = 0; // Leave # lines at start else @@ -2210,7 +2147,7 @@ do_put( curwin->w_cursor = old_pos; // remember how many chars were removed if (cnt == count && i == y_size - 1) - lendiff -= (int)STRLEN(ml_get(lnum)); + lendiff -= ml_get_len(lnum); } } if (cnt == 1) @@ -2302,7 +2239,7 @@ error: curwin->w_set_curswant = TRUE; // Make sure the cursor is not after the NUL. - int len = (int)STRLEN(ml_get_curline()); + int len = ml_get_curline_len(); if (curwin->w_cursor.col > len) { if (cur_ve_flags == VE_ALL) -- cgit v1.2.3