diff src/ops.c @ 29451:057c26b5c33a v9.0.0067

patch 9.0.0067: cannot show virtual text Commit: https://github.com/vim/vim/commit/7f9969c559b51446632ac7e8f76cde07e7d0078d Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 25 18:13:54 2022 +0100 patch 9.0.0067: cannot show virtual text Problem: Cannot show virtual text. Solution: Initial changes for virtual text support, using text properties.
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 Jul 2022 19:15:06 +0200
parents fba9e366ced4
children 8a243ecfe2dd
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -307,7 +307,8 @@ shift_block(oparg_T *oap, int amount)
 
     if (!left)
     {
-	int	tabs = 0, spaces = 0;
+	int		tabs = 0, spaces = 0;
+	chartabsize_T	cts;
 
 	/*
 	 *  1. Get start vcol
@@ -332,13 +333,20 @@ shift_block(oparg_T *oap, int amount)
 	    else
 		++bd.textstart;
 	}
-	for ( ; VIM_ISWHITE(*bd.textstart); )
+
+	// TODO: is passing bd.textstart for start of the line OK?
+	init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum,
+				   bd.start_vcol, bd.textstart, bd.textstart);
+	for ( ; VIM_ISWHITE(*cts.cts_ptr); )
 	{
-	    // TODO: is passing bd.textstart for start of the line OK?
-	    incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, bd.start_vcol);
+	    incr = lbr_chartabsize_adv(&cts);
 	    total += incr;
-	    bd.start_vcol += incr;
+	    cts.cts_vcol += incr;
 	}
+	bd.textstart = cts.cts_ptr;
+	bd.start_vcol = cts.cts_vcol;
+	clear_chartabsize_arg(&cts);
+
 	// OK, now total=all the VWS reqd, and textstart points at the 1st
 	// non-ws char in the block.
 #ifdef FEAT_VARTABS
@@ -381,6 +389,7 @@ shift_block(oparg_T *oap, int amount)
 	size_t	    shift_amount;
 	char_u	    *non_white = bd.textstart;
 	colnr_T	    non_white_col;
+	chartabsize_T cts;
 
 	/*
 	 * Firstly, let's find the first non-whitespace character that is
@@ -399,11 +408,16 @@ shift_block(oparg_T *oap, int amount)
 	// The character's column is in "bd.start_vcol".
 	non_white_col = bd.start_vcol;
 
-	while (VIM_ISWHITE(*non_white))
+	init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum,
+				   non_white_col, bd.textstart, non_white);
+	while (VIM_ISWHITE(*cts.cts_ptr))
 	{
-	    incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col);
-	    non_white_col += incr;
+	    incr = lbr_chartabsize_adv(&cts);
+	    cts.cts_vcol += incr;
 	}
+	non_white_col = cts.cts_vcol;
+	non_white = cts.cts_ptr;
+	clear_chartabsize_arg(&cts);
 
 	block_space_width = non_white_col - oap->start_vcol;
 	// We will shift by "total" or "block_space_width", whichever is less.
@@ -423,18 +437,19 @@ shift_block(oparg_T *oap, int amount)
 	// column number.
 	if (bd.startspaces)
 	    verbatim_copy_width -= bd.start_char_vcols;
-	while (verbatim_copy_width < destination_col)
+	init_chartabsize_arg(&cts, curwin, 0, verbatim_copy_width,
+					     bd.textstart, verbatim_copy_end);
+	while (cts.cts_vcol < destination_col)
 	{
-	    char_u *line = verbatim_copy_end;
-
-	    // TODO: is passing verbatim_copy_end for start of the line OK?
-	    incr = lbr_chartabsize(line, verbatim_copy_end,
-							 verbatim_copy_width);
-	    if (verbatim_copy_width + incr > destination_col)
+	    incr = lbr_chartabsize(&cts);
+	    if (cts.cts_vcol + incr > destination_col)
 		break;
-	    verbatim_copy_width += incr;
-	    MB_PTR_ADV(verbatim_copy_end);
+	    cts.cts_vcol += incr;
+	    MB_PTR_ADV(cts.cts_ptr);
 	}
+	verbatim_copy_width = cts.cts_vcol;
+	verbatim_copy_end = cts.cts_ptr;
+	clear_chartabsize_arg(&cts);
 
 	// If "destination_col" is different from the width of the initial
 	// part of the line that will be copied, it means we encountered a tab
@@ -703,8 +718,6 @@ op_delete(oparg_T *oap)
 	 * Put deleted text into register 1 and shift number registers if the
 	 * delete contains a line break, or when using a specific operator (Vi
 	 * compatible)
-	 * Use the register name from before adjust_clip_reg() may have
-	 * changed it.
 	 */
 	if (oap->motion_type == MLINE || oap->line_count > 1
 							   || oap->use_reg_one)
@@ -2213,6 +2226,7 @@ block_prep(
     char_u	*line;
     char_u	*prev_pstart;
     char_u	*prev_pend;
+    chartabsize_T cts;
 #ifdef FEAT_LINEBREAK
     int		lbr_saved = curwin->w_p_lbr;
 
@@ -2232,14 +2246,14 @@ block_prep(
     bdp->start_char_vcols = 0;
 
     line = ml_get(lnum);
-    pstart = line;
     prev_pstart = line;
-    while (bdp->start_vcol < oap->start_vcol && *pstart)
+    init_chartabsize_arg(&cts, curwin, lnum, bdp->start_vcol, line, line);
+    while (cts.cts_vcol < oap->start_vcol && *cts.cts_ptr != NUL)
     {
 	// Count a tab for what it's worth (if list mode not on)
-	incr = lbr_chartabsize(line, pstart, bdp->start_vcol);
-	bdp->start_vcol += incr;
-	if (VIM_ISWHITE(*pstart))
+	incr = lbr_chartabsize(&cts);
+	cts.cts_vcol += incr;
+	if (VIM_ISWHITE(*cts.cts_ptr))
 	{
 	    bdp->pre_whitesp += incr;
 	    bdp->pre_whitesp_c++;
@@ -2249,9 +2263,13 @@ block_prep(
 	    bdp->pre_whitesp = 0;
 	    bdp->pre_whitesp_c = 0;
 	}
-	prev_pstart = pstart;
-	MB_PTR_ADV(pstart);
+	prev_pstart = cts.cts_ptr;
+	MB_PTR_ADV(cts.cts_ptr);
     }
+    bdp->start_vcol = cts.cts_vcol;
+    pstart = cts.cts_ptr;
+    clear_chartabsize_arg(&cts);
+
     bdp->start_char_vcols = incr;
     if (bdp->start_vcol < oap->start_vcol)	// line too short
     {
@@ -2295,14 +2313,20 @@ block_prep(
 	}
 	else
 	{
+	    init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol,
+								  line, pend);
 	    prev_pend = pend;
-	    while (bdp->end_vcol <= oap->end_vcol && *pend != NUL)
+	    while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL)
 	    {
-		// Count a tab for what it's worth (if list mode not on)
-		prev_pend = pend;
-		incr = lbr_chartabsize_adv(line, &pend, bdp->end_vcol);
-		bdp->end_vcol += incr;
+		// count a tab for what it's worth (if list mode not on)
+		prev_pend = cts.cts_ptr;
+		incr = lbr_chartabsize_adv(&cts);
+		cts.cts_vcol += incr;
 	    }
+	    bdp->end_vcol = cts.cts_vcol;
+	    pend = cts.cts_ptr;
+	    clear_chartabsize_arg(&cts);
+
 	    if (bdp->end_vcol <= oap->end_vcol
 		    && (!is_del
 			|| oap->op_type == OP_APPEND