mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 9.0.0901: setting w_leftcol and handling side effects is confusing
Problem: Setting w_leftcol and handling side effects is confusing. Solution: Use a function to set w_leftcol() and handle side effects.
This commit is contained in:
31
src/misc2.c
31
src/misc2.c
@@ -673,25 +673,27 @@ adjust_cursor_col(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When curwin->w_leftcol has changed, adjust the cursor position.
|
* Set "curwin->w_leftcol" to "leftcol".
|
||||||
|
* Adjust the cursor position if needed.
|
||||||
* Return TRUE if the cursor was moved.
|
* Return TRUE if the cursor was moved.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
leftcol_changed(void)
|
set_leftcol(colnr_T leftcol)
|
||||||
{
|
{
|
||||||
long lastcol;
|
|
||||||
colnr_T s, e;
|
|
||||||
int retval = FALSE;
|
int retval = FALSE;
|
||||||
long siso = get_sidescrolloff_value();
|
|
||||||
|
// Return quickly when there is no change.
|
||||||
|
if (curwin->w_leftcol == leftcol)
|
||||||
|
return FALSE;
|
||||||
|
curwin->w_leftcol = leftcol;
|
||||||
|
|
||||||
changed_cline_bef_curs();
|
changed_cline_bef_curs();
|
||||||
lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1;
|
long lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1;
|
||||||
validate_virtcol();
|
validate_virtcol();
|
||||||
|
|
||||||
/*
|
// If the cursor is right or left of the screen, move it to last or first
|
||||||
* If the cursor is right or left of the screen, move it to last or first
|
// visible character.
|
||||||
* character.
|
long siso = get_sidescrolloff_value();
|
||||||
*/
|
|
||||||
if (curwin->w_virtcol > (colnr_T)(lastcol - siso))
|
if (curwin->w_virtcol > (colnr_T)(lastcol - siso))
|
||||||
{
|
{
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
@@ -703,11 +705,10 @@ leftcol_changed(void)
|
|||||||
(void)coladvance((colnr_T)(curwin->w_leftcol + siso));
|
(void)coladvance((colnr_T)(curwin->w_leftcol + siso));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If the start of the character under the cursor is not on the screen,
|
||||||
* If the start of the character under the cursor is not on the screen,
|
// advance the cursor one more char. If this fails (last char of the
|
||||||
* advance the cursor one more char. If this fails (last char of the
|
// line) adjust the scrolling.
|
||||||
* line) adjust the scrolling.
|
colnr_T s, e;
|
||||||
*/
|
|
||||||
getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
|
getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
|
||||||
if (e > (colnr_T)lastcol)
|
if (e > (colnr_T)lastcol)
|
||||||
{
|
{
|
||||||
|
@@ -2035,8 +2035,6 @@ do_mousescroll_horiz(long_u leftcol)
|
|||||||
if (curwin->w_leftcol == (colnr_T)leftcol)
|
if (curwin->w_leftcol == (colnr_T)leftcol)
|
||||||
return FALSE; // already there
|
return FALSE; // already there
|
||||||
|
|
||||||
curwin->w_leftcol = (colnr_T)leftcol;
|
|
||||||
|
|
||||||
// When the line of the cursor is too short, move the cursor to the
|
// When the line of the cursor is too short, move the cursor to the
|
||||||
// longest visible line.
|
// longest visible line.
|
||||||
if (
|
if (
|
||||||
@@ -2050,7 +2048,7 @@ do_mousescroll_horiz(long_u leftcol)
|
|||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return leftcol_changed();
|
return set_leftcol((colnr_T)leftcol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2098,7 +2096,7 @@ do_mousescroll(int mode, cmdarg_T *cap)
|
|||||||
send_keys_to_term(curbuf->b_term, cap->cmdchar, mod_mask, FALSE);
|
send_keys_to_term(curbuf->b_term, cap->cmdchar, mod_mask, FALSE);
|
||||||
else
|
else
|
||||||
# endif
|
# endif
|
||||||
// For insert mode, don't scroll the window in which completion is being
|
// For Insert mode, don't scroll the window in which completion is being
|
||||||
// done.
|
// done.
|
||||||
if (mode == MODE_NORMAL || !pum_visible() || curwin != old_curwin)
|
if (mode == MODE_NORMAL || !pum_visible() || curwin != old_curwin)
|
||||||
{
|
{
|
||||||
|
28
src/normal.c
28
src/normal.c
@@ -1930,11 +1930,8 @@ check_scrollbind(linenr_T topline_diff, long leftcol_diff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the horizontal scroll
|
// do the horizontal scroll
|
||||||
if (want_hor && curwin->w_leftcol != tgt_leftcol)
|
if (want_hor)
|
||||||
{
|
(void)set_leftcol(tgt_leftcol);
|
||||||
curwin->w_leftcol = tgt_leftcol;
|
|
||||||
leftcol_changed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset current-window
|
// reset current-window
|
||||||
@@ -2458,7 +2455,7 @@ scroll_redraw(int up, long count)
|
|||||||
scrollup(count, TRUE);
|
scrollup(count, TRUE);
|
||||||
else
|
else
|
||||||
scrolldown(count, TRUE);
|
scrolldown(count, TRUE);
|
||||||
if (get_scrolloff_value())
|
if (get_scrolloff_value() > 0)
|
||||||
{
|
{
|
||||||
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
|
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
|
||||||
// valid, otherwise the screen jumps back at the end of the file.
|
// valid, otherwise the screen jumps back at the end of the file.
|
||||||
@@ -2734,28 +2731,19 @@ nv_zet(cmdarg_T *cap)
|
|||||||
case 'h':
|
case 'h':
|
||||||
case K_LEFT:
|
case K_LEFT:
|
||||||
if (!curwin->w_p_wrap)
|
if (!curwin->w_p_wrap)
|
||||||
{
|
(void)set_leftcol((colnr_T)cap->count1 > curwin->w_leftcol
|
||||||
if ((colnr_T)cap->count1 > curwin->w_leftcol)
|
? 0 : curwin->w_leftcol - (colnr_T)cap->count1);
|
||||||
curwin->w_leftcol = 0;
|
|
||||||
else
|
|
||||||
curwin->w_leftcol -= (colnr_T)cap->count1;
|
|
||||||
leftcol_changed();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// "zL" - scroll screen left half-page
|
// "zL" - scroll window left half-page
|
||||||
case 'L': cap->count1 *= curwin->w_width / 2;
|
case 'L': cap->count1 *= curwin->w_width / 2;
|
||||||
// FALLTHROUGH
|
// FALLTHROUGH
|
||||||
|
|
||||||
// "zl" - scroll screen to the left
|
// "zl" - scroll window to the left if not wrapping
|
||||||
case 'l':
|
case 'l':
|
||||||
case K_RIGHT:
|
case K_RIGHT:
|
||||||
if (!curwin->w_p_wrap)
|
if (!curwin->w_p_wrap)
|
||||||
{
|
(void)set_leftcol(curwin->w_leftcol + (colnr_T)cap->count1);
|
||||||
// scroll the window left
|
|
||||||
curwin->w_leftcol += (colnr_T)cap->count1;
|
|
||||||
leftcol_changed();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// "zs" - scroll screen, cursor at the start
|
// "zs" - scroll screen, cursor at the start
|
||||||
|
@@ -19,7 +19,7 @@ void check_cursor_col_win(win_T *win);
|
|||||||
void check_cursor(void);
|
void check_cursor(void);
|
||||||
void check_visual_pos(void);
|
void check_visual_pos(void);
|
||||||
void adjust_cursor_col(void);
|
void adjust_cursor_col(void);
|
||||||
int leftcol_changed(void);
|
int set_leftcol(colnr_T leftcol);
|
||||||
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
|
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
|
||||||
int vim_isspace(int x);
|
int vim_isspace(int x);
|
||||||
int simplify_key(int key, int *modifiers);
|
int simplify_key(int key, int *modifiers);
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
901,
|
||||||
/**/
|
/**/
|
||||||
900,
|
900,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user