Blame SOURCES/7.4.579

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.579
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.579
22c937
Problem:    Wrong cursor positioning when 'linebreak' is set and lines wrap.
22c937
Solution:   Solve it. (Christian Brabandt)
22c937
Files:	    src/charset.c, src/screen.c
22c937
22c937
22c937
*** ../vim-7.4.578/src/charset.c	2014-10-31 12:41:57.427319153 +0100
22c937
--- src/charset.c	2015-01-14 19:34:38.916109031 +0100
22c937
***************
22c937
*** 1178,1205 ****
22c937
      added = 0;
22c937
      if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0)
22c937
      {
22c937
! 	numberextra = win_col_off(wp);
22c937
  	col += numberextra + mb_added;
22c937
  	if (col >= (colnr_T)W_WIDTH(wp))
22c937
  	{
22c937
  	    col -= W_WIDTH(wp);
22c937
  	    numberextra = W_WIDTH(wp) - (numberextra - win_col_off2(wp));
22c937
! 	    if (numberextra > 0)
22c937
  		col %= numberextra;
22c937
  	    if (*p_sbr != NUL)
22c937
  	    {
22c937
! 		colnr_T sbrlen = (colnr_T)MB_CHARLEN(p_sbr);
22c937
  		if (col >= sbrlen)
22c937
  		    col -= sbrlen;
22c937
  	    }
22c937
! 	    if (numberextra > 0)
22c937
  		col = col % numberextra;
22c937
  	}
22c937
! 	if (col == 0 || col + size > (colnr_T)W_WIDTH(wp))
22c937
  	{
22c937
  	    added = 0;
22c937
  	    if (*p_sbr != NUL)
22c937
! 		added += vim_strsize(p_sbr);
22c937
  	    if (wp->w_p_bri)
22c937
  		added += get_breakindent_win(wp, line);
22c937
  
22c937
--- 1178,1227 ----
22c937
      added = 0;
22c937
      if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0)
22c937
      {
22c937
! 	colnr_T sbrlen = 0;
22c937
! 	int	numberwidth = win_col_off(wp);
22c937
! 
22c937
! 	numberextra = numberwidth;
22c937
  	col += numberextra + mb_added;
22c937
  	if (col >= (colnr_T)W_WIDTH(wp))
22c937
  	{
22c937
  	    col -= W_WIDTH(wp);
22c937
  	    numberextra = W_WIDTH(wp) - (numberextra - win_col_off2(wp));
22c937
! 	    if (col >= numberextra && numberextra > 0)
22c937
  		col %= numberextra;
22c937
  	    if (*p_sbr != NUL)
22c937
  	    {
22c937
! 		sbrlen = (colnr_T)MB_CHARLEN(p_sbr);
22c937
  		if (col >= sbrlen)
22c937
  		    col -= sbrlen;
22c937
  	    }
22c937
! 	    if (col >= numberextra && numberextra > 0)
22c937
  		col = col % numberextra;
22c937
+ 	    else if (col > 0 && numberextra > 0)
22c937
+ 		col += numberwidth - win_col_off2(wp);
22c937
+ 
22c937
+ 	    numberwidth -= win_col_off2(wp);
22c937
  	}
22c937
! 	if (col == 0 || col + size + sbrlen > (colnr_T)W_WIDTH(wp))
22c937
  	{
22c937
  	    added = 0;
22c937
  	    if (*p_sbr != NUL)
22c937
! 	    {
22c937
! 		if (size + sbrlen + numberwidth > (colnr_T)W_WIDTH(wp))
22c937
! 		{
22c937
! 		    /* calculate effective window width */
22c937
! 		    int width = (colnr_T)W_WIDTH(wp) - sbrlen - numberwidth;
22c937
! 		    int prev_width = col ? ((colnr_T)W_WIDTH(wp) - (sbrlen + col)) : 0;
22c937
! 		    if (width == 0)
22c937
! 			width = (colnr_T)W_WIDTH(wp);
22c937
! 		    added += ((size - prev_width) / width) * vim_strsize(p_sbr);
22c937
! 		    if ((size - prev_width) % width)
22c937
! 			/* wrapped, add another length of 'sbr' */
22c937
! 			added += vim_strsize(p_sbr);
22c937
! 		}
22c937
! 		else
22c937
! 		    added += vim_strsize(p_sbr);
22c937
! 	    }
22c937
  	    if (wp->w_p_bri)
22c937
  		added += get_breakindent_win(wp, line);
22c937
  
22c937
*** ../vim-7.4.578/src/screen.c	2015-01-07 19:04:25.299934570 +0100
22c937
--- src/screen.c	2015-01-14 19:27:46.428652958 +0100
22c937
***************
22c937
*** 2842,2847 ****
22c937
--- 2842,2850 ----
22c937
      unsigned	off;			/* offset in ScreenLines/ScreenAttrs */
22c937
      int		c = 0;			/* init for GCC */
22c937
      long	vcol = 0;		/* virtual column (for tabs) */
22c937
+ #ifdef FEAT_LINEBREAK
22c937
+     long	vcol_sbr = -1;		/* virtual column after showbreak */
22c937
+ #endif
22c937
      long	vcol_prev = -1;		/* "vcol" of previous character */
22c937
      char_u	*line;			/* current line */
22c937
      char_u	*ptr;			/* current position in "line" */
22c937
***************
22c937
*** 3759,3764 ****
22c937
--- 3762,3768 ----
22c937
  		    n_extra = (int)STRLEN(p_sbr);
22c937
  		    char_attr = hl_attr(HLF_AT);
22c937
  		    need_showbreak = FALSE;
22c937
+ 		    vcol_sbr = vcol + MB_CHARLEN(p_sbr);
22c937
  		    /* Correct end of highlighted area for 'showbreak',
22c937
  		     * required when 'linebreak' is also set. */
22c937
  		    if (tocol == vcol)
22c937
***************
22c937
*** 4516,4524 ****
22c937
  		if (c == TAB && (!wp->w_p_list || lcs_tab1))
22c937
  		{
22c937
  		    int tab_len = 0;
22c937
  		    /* tab amount depends on current column */
22c937
  		    tab_len = (int)wp->w_buffer->b_p_ts
22c937
! 					- vcol % (int)wp->w_buffer->b_p_ts - 1;
22c937
  #ifdef FEAT_LINEBREAK
22c937
  		    if (!wp->w_p_lbr || !wp->w_p_list)
22c937
  #endif
22c937
--- 4520,4536 ----
22c937
  		if (c == TAB && (!wp->w_p_list || lcs_tab1))
22c937
  		{
22c937
  		    int tab_len = 0;
22c937
+ 		    long vcol_adjusted = vcol; /* removed showbreak length */
22c937
+ #ifdef FEAT_LINEBREAK
22c937
+ 		    /* only adjust the tab_len, when at the first column
22c937
+ 		     * after the showbreak value was drawn */
22c937
+ 		    if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
22c937
+ 			vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
22c937
+ #endif
22c937
  		    /* tab amount depends on current column */
22c937
  		    tab_len = (int)wp->w_buffer->b_p_ts
22c937
! 					- vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
22c937
! 
22c937
  #ifdef FEAT_LINEBREAK
22c937
  		    if (!wp->w_p_lbr || !wp->w_p_list)
22c937
  #endif
22c937
*** ../vim-7.4.578/src/version.c	2015-01-14 19:00:33.842522901 +0100
22c937
--- src/version.c	2015-01-14 19:28:47.291982266 +0100
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     579,
22c937
  /**/
22c937
22c937
-- 
22c937
From "know your smileys":
22c937
 O:-)	Saint
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///