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