mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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.
0c34d56264
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
3621604029
commit
26a9f0e94e
@ -439,23 +439,27 @@ void 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.
|
||||||
bool leftcol_changed(void)
|
bool set_leftcol(colnr_T leftcol)
|
||||||
{
|
{
|
||||||
// TODO(hinidu): I think it should be colnr_T or int, but p_siso is long.
|
// Return quickly when there is no change.
|
||||||
// Perhaps we can change p_siso to int.
|
if (curwin->w_leftcol == leftcol) {
|
||||||
int64_t lastcol;
|
return false;
|
||||||
colnr_T s, e;
|
}
|
||||||
bool retval = false;
|
curwin->w_leftcol = leftcol;
|
||||||
|
|
||||||
changed_cline_bef_curs();
|
changed_cline_bef_curs();
|
||||||
lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1;
|
// TODO(hinidu): I think it should be colnr_T or int, but p_siso is long.
|
||||||
|
// Perhaps we can change p_siso to int.
|
||||||
|
int64_t lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1;
|
||||||
validate_virtcol();
|
validate_virtcol();
|
||||||
|
|
||||||
|
bool retval = false;
|
||||||
// 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
|
||||||
// character.
|
// visible character.
|
||||||
long siso = get_sidescrolloff_value(curwin);
|
long siso = get_sidescrolloff_value(curwin);
|
||||||
if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) {
|
if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) {
|
||||||
retval = true;
|
retval = true;
|
||||||
@ -468,6 +472,7 @@ bool leftcol_changed(void)
|
|||||||
// 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) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -1648,8 +1648,6 @@ bool mouse_scroll_horiz(int dir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (!virtual_active()
|
if (!virtual_active()
|
||||||
@ -1658,7 +1656,7 @@ bool mouse_scroll_horiz(int dir)
|
|||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return leftcol_changed();
|
return set_leftcol(leftcol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts the clicked column position when 'conceallevel' > 0
|
/// Adjusts the clicked column position when 'conceallevel' > 0
|
||||||
|
@ -2158,9 +2158,8 @@ void 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) {
|
||||||
curwin->w_leftcol = tgt_leftcol;
|
(void)set_leftcol(tgt_leftcol);
|
||||||
leftcol_changed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2643,7 +2642,7 @@ void scroll_redraw(int up, long count)
|
|||||||
scrollup(count, true) :
|
scrollup(count, true) :
|
||||||
scrolldown(count, true);
|
scrolldown(count, true);
|
||||||
|
|
||||||
if (get_scrolloff_value(curwin)) {
|
if (get_scrolloff_value(curwin) > 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.
|
||||||
cursor_correct();
|
cursor_correct();
|
||||||
@ -2894,27 +2893,21 @@ static void 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) {
|
||||||
if ((colnr_T)cap->count1 > curwin->w_leftcol) {
|
(void)set_leftcol((colnr_T)cap->count1 > curwin->w_leftcol
|
||||||
curwin->w_leftcol = 0;
|
? 0 : curwin->w_leftcol - (colnr_T)cap->count1);
|
||||||
} 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':
|
case 'L':
|
||||||
cap->count1 *= curwin->w_width_inner / 2;
|
cap->count1 *= curwin->w_width_inner / 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) {
|
||||||
// scroll the window left
|
(void)set_leftcol(curwin->w_leftcol + (colnr_T)cap->count1);
|
||||||
curwin->w_leftcol += (colnr_T)cap->count1;
|
|
||||||
leftcol_changed();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user