fix(api/buffer): fix handling of viewport of non-current buffer

A lot of functions in move.c only worked for curwin, alternatively
took a `wp` arg but still only work if that happens to be curwin.

Refactor those that are needed for update_topline(wp) to work
for any window.

fixes #27723
fixes #27720
This commit is contained in:
bfredl 2024-03-11 13:19:49 +01:00
parent d5488633f6
commit 08fc1ebbaa
50 changed files with 844 additions and 814 deletions

View File

@ -1269,10 +1269,13 @@ static void fix_cursor(win_T *win, linenr_T lo, linenr_T hi, linenr_T extra)
} else if (extra < 0) {
check_cursor_lnum(win);
}
check_cursor_col_win(win);
check_cursor_col(win);
changed_cline_bef_curs(win);
win->w_valid &= ~(VALID_BOTLINE_AP);
update_topline(win);
} else {
invalidate_botline(win);
}
invalidate_botline(win);
}
/// Fix cursor position after replacing text
@ -1307,7 +1310,7 @@ static void fix_cursor_cols(win_T *win, linenr_T start_row, colnr_T start_col, l
// it's easier to work with a single value here.
// col and coladd are fixed by a later call
// to check_cursor_col_win when necessary
// to check_cursor_col when necessary
win->w_cursor.col += win->w_cursor.coladd;
win->w_cursor.coladd = 0;
@ -1343,7 +1346,7 @@ static void fix_cursor_cols(win_T *win, linenr_T start_row, colnr_T start_col, l
}
}
check_cursor_col_win(win);
check_cursor_col(win);
changed_cline_bef_curs(win);
invalidate_botline(win);
}

View File

@ -1246,7 +1246,7 @@ Boolean nvim_win_add_ns(Window window, Integer ns_id, Error *err)
set_put(uint32_t, &win->w_ns_set, (uint32_t)ns_id);
changed_window_setting_win(win);
changed_window_setting(win);
return true;
}
@ -1291,7 +1291,7 @@ Boolean nvim_win_remove_ns(Window window, Integer ns_id, Error *err)
set_del(uint32_t, &win->w_ns_set, (uint32_t)ns_id);
changed_window_setting_win(win);
changed_window_setting(win);
return true;
}

View File

@ -138,7 +138,7 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
win->w_cursor.col = (colnr_T)col;
win->w_cursor.coladd = 0;
// When column is out of range silently correct it.
check_cursor_col_win(win);
check_cursor_col(win);
// Make sure we stick in this column.
win->w_set_curswant = true;
@ -148,7 +148,7 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
switchwin_T switchwin;
switch_win(&switchwin, win, NULL, true);
update_topline(curwin);
validate_cursor();
validate_cursor(curwin);
restore_win(&switchwin, true);
redraw_later(win, UPD_VALID);

View File

@ -1432,7 +1432,7 @@ win_found:
// the buffer contents may have changed
VIsual_active = aco->save_VIsual_active;
check_cursor();
check_cursor(curwin);
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count;
curwin->w_topfill = 0;
@ -1464,12 +1464,12 @@ win_found:
// In case the autocommand moves the cursor to a position that does not
// exist in curbuf
VIsual_active = aco->save_VIsual_active;
check_cursor();
check_cursor(curwin);
}
}
VIsual_active = aco->save_VIsual_active;
check_cursor(); // just in case lines got deleted
check_cursor(curwin); // just in case lines got deleted
if (VIsual_active) {
check_pos(curbuf, &VIsual);
}

View File

@ -1752,7 +1752,7 @@ void enter_buffer(buf_T *buf)
maketitle();
// when autocmds didn't change it
if (curwin->w_topline == 1 && !curwin->w_topline_was_set) {
scroll_cursor_halfway(false, false); // redisplay at correct position
scroll_cursor_halfway(curwin, false, false); // redisplay at correct position
}
// Change directories when the 'acd' option is set.
@ -2172,7 +2172,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
// cursor is at to BOL and w_cursor.lnum is checked due to getfile()
if (!p_sol && col != 0) {
curwin->w_cursor.col = col;
check_cursor_col();
check_cursor_col(curwin);
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
}
@ -2197,7 +2197,7 @@ void buflist_getfpos(void)
curwin->w_cursor.col = 0;
} else {
curwin->w_cursor.col = fpos->col;
check_cursor_col();
check_cursor_col(curwin);
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
}
@ -3257,7 +3257,7 @@ void fileinfo(int fullname, int shorthelp, bool dont_truncate)
(int64_t)curwin->w_cursor.lnum,
(int64_t)curbuf->b_ml.ml_line_count,
n);
validate_virtcol();
validate_virtcol(curwin);
size_t len = strlen(buffer);
col_print(buffer + len, IOSIZE - len,
(int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);

View File

@ -707,7 +707,7 @@ void ins_char(int c)
void ins_char_bytes(char *buf, size_t charlen)
{
// Break tabs if needed.
if (virtual_active() && curwin->w_cursor.coladd > 0) {
if (virtual_active(curwin) && curwin->w_cursor.coladd > 0) {
coladvance_force(getviscol());
}
@ -815,7 +815,7 @@ void ins_str(char *s)
int newlen = (int)strlen(s);
linenr_T lnum = curwin->w_cursor.lnum;
if (virtual_active() && curwin->w_cursor.coladd > 0) {
if (virtual_active(curwin) && curwin->w_cursor.coladd > 0) {
coladvance_force(getviscol());
}
@ -918,7 +918,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
// fixpos is true, we don't want to end up positioned at the NUL,
// unless "restart_edit" is set or 'virtualedit' contains "onemore".
if (col > 0 && fixpos && restart_edit == 0
&& (get_ve_flags() & VE_ONEMORE) == 0) {
&& (get_ve_flags(curwin) & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
curwin->w_cursor.coladd = 0;
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);

View File

@ -57,7 +57,7 @@ int getviscol2(colnr_T col, colnr_T coladd)
/// The caller must have saved the cursor line for undo!
int coladvance_force(colnr_T wcol)
{
int rc = coladvance2(&curwin->w_cursor, true, false, wcol);
int rc = coladvance2(curwin, &curwin->w_cursor, true, false, wcol);
if (wcol == MAXCOL) {
curwin->w_valid &= ~VALID_VIRTCOL;
@ -76,25 +76,26 @@ int coladvance_force(colnr_T wcol)
/// beginning at coladd 0.
///
/// @return OK if desired column is reached, FAIL if not
int coladvance(colnr_T wcol)
int coladvance(win_T *wp, colnr_T wcol)
{
int rc = getvpos(&curwin->w_cursor, wcol);
int rc = getvpos(wp, &wp->w_cursor, wcol);
if (wcol == MAXCOL || rc == FAIL) {
curwin->w_valid &= ~VALID_VIRTCOL;
} else if (*get_cursor_pos_ptr() != TAB) {
wp->w_valid &= ~VALID_VIRTCOL;
} else if (*(ml_get_buf(wp->w_buffer, wp->w_cursor.lnum) + wp->w_cursor.col) != TAB) {
// Virtcol is valid when not on a TAB
curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol;
wp->w_valid |= VALID_VIRTCOL;
wp->w_virtcol = wcol;
}
return rc;
}
/// @param addspaces change the text to achieve our goal?
/// @param addspaces change the text to achieve our goal? only for wp=curwin!
/// @param finetune change char offset for the exact column
/// @param wcol_arg column to move to (can be negative)
static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_arg)
static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_arg)
{
assert(wp == curwin || !addspaces);
colnr_T wcol = wcol_arg;
int idx;
colnr_T col = 0;
@ -104,30 +105,30 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
|| (State & MODE_TERMINAL)
|| restart_edit != NUL
|| (VIsual_active && *p_sel != 'o')
|| ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL);
|| ((get_ve_flags(wp) & VE_ONEMORE) && wcol < MAXCOL);
char *line = ml_get_buf(curbuf, pos->lnum);
char *line = ml_get_buf(wp->w_buffer, pos->lnum);
if (wcol >= MAXCOL) {
idx = (int)strlen(line) - 1 + one_more;
col = wcol;
if ((addspaces || finetune) && !VIsual_active) {
curwin->w_curswant = linetabsize(curwin, pos->lnum) + one_more;
if (curwin->w_curswant > 0) {
curwin->w_curswant--;
wp->w_curswant = linetabsize(wp, pos->lnum) + one_more;
if (wp->w_curswant > 0) {
wp->w_curswant--;
}
}
} else {
int width = curwin->w_width_inner - win_col_off(curwin);
int width = wp->w_width_inner - win_col_off(wp);
int csize = 0;
if (finetune
&& curwin->w_p_wrap
&& curwin->w_width_inner != 0
&& wp->w_p_wrap
&& wp->w_width_inner != 0
&& wcol >= (colnr_T)width
&& width > 0) {
csize = linetabsize(curwin, pos->lnum);
csize = linetabsize(wp, pos->lnum);
if (csize > 0) {
csize--;
}
@ -143,7 +144,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
}
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, pos->lnum, line);
CSType cstype = init_charsize_arg(&csarg, wp, pos->lnum, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
col = 0;
while (col <= wcol && *ci.ptr != NUL) {
@ -159,14 +160,14 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
// is needed to ensure that a virtual position off the end of
// a line has the correct indexing. The one_more comparison
// replaces an explicit add of one_more later on.
if (col > wcol || (!virtual_active() && one_more == 0)) {
if (col > wcol || (!virtual_active(wp) && one_more == 0)) {
idx -= 1;
// Don't count the chars from 'showbreak'.
csize -= head;
col -= csize;
}
if (virtual_active()
if (virtual_active(wp)
&& addspaces
&& wcol >= 0
&& ((col != wcol && col != wcol + 1) || csize > 1)) {
@ -229,14 +230,14 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
if (!one_more) {
colnr_T scol, ecol;
getvcol(curwin, pos, &scol, NULL, &ecol);
getvcol(wp, pos, &scol, NULL, &ecol);
pos->coladd = ecol - scol;
}
} else {
int b = (int)wcol - (int)col;
// The difference between wcol and col is used to set coladd.
if (b > 0 && b < (MAXCOL - 2 * curwin->w_width_inner)) {
if (b > 0 && b < (MAXCOL - 2 * wp->w_width_inner)) {
pos->coladd = b;
}
@ -245,7 +246,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
}
// Prevent from moving onto a trail byte.
mark_mb_adjustpos(curbuf, pos);
mark_mb_adjustpos(wp->w_buffer, pos);
if (wcol < 0 || col < wcol) {
return FAIL;
@ -256,9 +257,9 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
/// Return in "pos" the position of the cursor advanced to screen column "wcol".
///
/// @return OK if desired column is reached, FAIL if not
int getvpos(pos_T *pos, colnr_T wcol)
int getvpos(win_T *wp, pos_T *pos, colnr_T wcol)
{
return coladvance2(pos, false, virtual_active(), wcol);
return coladvance2(wp, pos, false, virtual_active(wp), wcol);
}
/// Increment the cursor position. See inc() for return values.
@ -294,7 +295,7 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)
// Loop until we reach to_line, skipping folds.
for (; from_line < to_line; from_line++, retval++) {
// If from_line is in a fold, set it to the last line of that fold.
hasFoldingWin(wp, from_line, NULL, &from_line, true, NULL);
hasFolding(wp, from_line, NULL, &from_line);
}
// If to_line is in a closed fold, the line count is off by +1. Correct it.
@ -329,7 +330,7 @@ void check_cursor_lnum(win_T *win)
if (win->w_cursor.lnum > buf->b_ml.ml_line_count) {
// If there is a closed fold at the end of the file, put the cursor in
// its first line. Otherwise in the last line.
if (!hasFolding(buf->b_ml.ml_line_count, &win->w_cursor.lnum, NULL)) {
if (!hasFolding(win, buf->b_ml.ml_line_count, &win->w_cursor.lnum, NULL)) {
win->w_cursor.lnum = buf->b_ml.ml_line_count;
}
}
@ -338,19 +339,13 @@ void check_cursor_lnum(win_T *win)
}
}
/// Make sure curwin->w_cursor.col is valid.
void check_cursor_col(void)
{
check_cursor_col_win(curwin);
}
/// Make sure win->w_cursor.col is valid. Special handling of insert-mode.
/// @see mb_check_adjust_col
void check_cursor_col_win(win_T *win)
void check_cursor_col(win_T *win)
{
colnr_T oldcol = win->w_cursor.col;
colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
unsigned cur_ve_flags = get_ve_flags();
unsigned cur_ve_flags = get_ve_flags(win);
colnr_T len = (colnr_T)strlen(ml_get_buf(win->w_buffer, win->w_cursor.lnum));
if (len == 0) {
@ -363,7 +358,7 @@ void check_cursor_col_win(win_T *win)
if ((State & MODE_INSERT) || restart_edit
|| (VIsual_active && *p_sel != 'o')
|| (cur_ve_flags & VE_ONEMORE)
|| virtual_active()) {
|| virtual_active(win)) {
win->w_cursor.col = len;
} else {
win->w_cursor.col = len - 1;
@ -403,10 +398,10 @@ void check_cursor_col_win(win_T *win)
}
/// Make sure curwin->w_cursor in on a valid character
void check_cursor(void)
void check_cursor(win_T *wp)
{
check_cursor_lnum(curwin);
check_cursor_col();
check_cursor_lnum(wp);
check_cursor_col(wp);
}
/// Check if VIsual position is valid, correct it if not.
@ -453,8 +448,8 @@ bool set_leftcol(colnr_T leftcol)
changed_cline_bef_curs(curwin);
// 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();
int64_t lastcol = curwin->w_leftcol + curwin->w_width_inner - win_col_off(curwin) - 1;
validate_virtcol(curwin);
bool retval = false;
// If the cursor is right or left of the screen, move it to last or first
@ -462,10 +457,10 @@ bool set_leftcol(colnr_T leftcol)
int siso = get_sidescrolloff_value(curwin);
if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) {
retval = true;
coladvance((colnr_T)(lastcol - siso));
coladvance(curwin, (colnr_T)(lastcol - siso));
} else if (curwin->w_virtcol < curwin->w_leftcol + siso) {
retval = true;
coladvance((colnr_T)(curwin->w_leftcol + siso));
coladvance(curwin, (colnr_T)(curwin->w_leftcol + siso));
}
// If the start of the character under the cursor is not on the screen,
@ -475,10 +470,10 @@ bool set_leftcol(colnr_T leftcol)
getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e);
if (e > (colnr_T)lastcol) {
retval = true;
coladvance(s - 1);
coladvance(curwin, s - 1);
} else if (s < curwin->w_leftcol) {
retval = true;
if (coladvance(e + 1) == FAIL) { // there isn't another character
if (coladvance(curwin, e + 1) == FAIL) { // there isn't another character
curwin->w_leftcol = s; // adjust w_leftcol instead
changed_cline_bef_curs(curwin);
}

View File

@ -890,9 +890,9 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines, TriState has_fo
}
assert(lnum > 0);
bool below_fold = lnum > 1 && hasFoldingWin(wp, lnum - 1, NULL, NULL, true, NULL);
bool below_fold = lnum > 1 && hasFolding(wp, lnum - 1, NULL, NULL);
if (has_fold == kNone) {
has_fold = hasFoldingWin(wp, lnum, NULL, NULL, true, NULL);
has_fold = hasFolding(wp, lnum, NULL, NULL);
}
const int row = lnum - 1;

View File

@ -1347,7 +1347,7 @@ void ex_diffsplit(exarg_T *eap)
set_bufref(&old_curbuf, curbuf);
// Need to compute w_fraction when no redraw happened yet.
validate_cursor();
validate_cursor(curwin);
set_fraction(curwin);
// don't use a new tab page, each tab page has its own diffs
@ -1457,7 +1457,7 @@ void diff_win_options(win_T *wp, bool addbuf)
foldUpdateAll(wp);
// make sure topline is not halfway through a fold
changed_window_setting_win(wp);
changed_window_setting(wp);
if (vim_strchr(p_sbo, 'h') == NULL) {
do_cmdline_cmd("set sbo+=hor");
}
@ -1522,7 +1522,7 @@ void ex_diffoff(exarg_T *eap)
// make sure topline is not halfway a fold and cursor is
// invalidated
changed_window_setting_win(wp);
changed_window_setting(wp);
// Note: 'sbo' is not restored, it's a global option.
diff_buf_adjust(wp);
@ -2137,7 +2137,7 @@ int diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus)
}
// A closed fold never has filler lines.
if (hasFoldingWin(wp, lnum, NULL, NULL, true, NULL)) {
if (hasFolding(wp, lnum, NULL, NULL)) {
return 0;
}
@ -2451,8 +2451,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin)
changed_line_abv_curs_win(towin);
check_topfill(towin, false);
hasFoldingWin(towin, towin->w_topline, &towin->w_topline,
NULL, true, NULL);
hasFolding(towin, towin->w_topline, &towin->w_topline, NULL);
}
/// This is called when 'diffopt' is changed.
@ -2988,7 +2987,7 @@ theend:
// Check that the cursor is on a valid character and update its
// position. When there were filler lines the topline has become
// invalid.
check_cursor();
check_cursor(curwin);
changed_line_abv_curs();
if (diff_need_update) {

View File

@ -1393,7 +1393,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
// the end of the line may be before the start of the displayed part.
if (wlv.vcol < start_col && (wp->w_p_cuc
|| wlv.color_cols
|| virtual_active()
|| virtual_active(wp)
|| (VIsual_active && wp->w_buffer == curwin->w_buffer))) {
wlv.vcol = start_col;
}
@ -2339,7 +2339,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
&& wlv.line_attr == 0
&& wlv.line_attr_lowprio == 0) {
// In virtualedit, visual selections may extend beyond end of line
if (!(area_highlighting && virtual_active()
if (!(area_highlighting && virtual_active(wp)
&& wlv.tocol != MAXCOL && wlv.vcol < wlv.tocol)) {
wlv.p_extra = "";
}
@ -2382,7 +2382,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
mb_schar = schar_from_ascii(mb_c);
} else if (VIsual_active
&& (VIsual_mode == Ctrl_V || VIsual_mode == 'v')
&& virtual_active()
&& virtual_active(wp)
&& wlv.tocol != MAXCOL
&& wlv.vcol < wlv.tocol
&& wlv.col < grid->cols) {

View File

@ -823,7 +823,7 @@ void setcursor(void)
void setcursor_mayforce(bool force)
{
if (force || redrawing()) {
validate_cursor();
validate_cursor(curwin);
ScreenGrid *grid = &curwin->w_grid;
int row = curwin->w_wrow;
@ -851,7 +851,7 @@ void show_cursor_info_later(bool force)
&& *ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum) == NUL;
// Only draw when something changed.
validate_virtcol_win(curwin);
validate_virtcol(curwin);
if (force
|| curwin->w_cursor.lnum != curwin->w_stl_cursor.lnum
|| curwin->w_cursor.col != curwin->w_stl_cursor.col
@ -1611,14 +1611,14 @@ static void win_update(win_T *wp)
}
}
hasFoldingWin(wp, mod_top, &mod_top, NULL, true, NULL);
hasFolding(wp, mod_top, &mod_top, NULL);
if (mod_top > lnumt) {
mod_top = lnumt;
}
// Now do the same for the bottom line (one above mod_bot).
mod_bot--;
hasFoldingWin(wp, mod_bot, NULL, &mod_bot, true, NULL);
hasFolding(wp, mod_bot, NULL, &mod_bot);
mod_bot++;
if (mod_bot < lnumb) {
mod_bot = lnumb;
@ -1691,7 +1691,7 @@ static void win_update(win_T *wp)
if (j >= wp->w_grid.rows - 2) {
break;
}
hasFoldingWin(wp, ln, NULL, &ln, true, NULL);
hasFolding(wp, ln, NULL, &ln);
}
} else {
j = wp->w_lines[0].wl_lnum - wp->w_topline;
@ -1903,7 +1903,7 @@ static void win_update(win_T *wp)
// Highlight to the end of the line, unless 'virtualedit' has
// "block".
if (curwin->w_curswant == MAXCOL) {
if (get_ve_flags() & VE_BLOCK) {
if (get_ve_flags(curwin) & VE_BLOCK) {
pos_T pos;
int cursor_above = curwin->w_cursor.lnum < VIsual.lnum;
@ -2148,7 +2148,7 @@ static void win_update(win_T *wp)
// rows, and may insert/delete lines
int j = idx;
for (l = lnum; l < mod_bot; l++) {
if (hasFoldingWin(wp, l, NULL, &l, true, NULL)) {
if (hasFolding(wp, l, NULL, &l)) {
new_rows++;
} else if (l == wp->w_topline) {
int n = plines_win_nofill(wp, l, false) + wp->w_topfill;

View File

@ -185,7 +185,7 @@ static void insert_enter(InsertState *s)
curwin->w_cursor = save_cursor;
State = MODE_INSERT;
check_cursor_col();
check_cursor_col(curwin);
State = save_state;
}
}
@ -282,7 +282,7 @@ static void insert_enter(InsertState *s)
// correct in very rare cases).
// Also do this if curswant is greater than the current virtual
// column. Eg after "^O$" or "^O80|".
validate_virtcol();
validate_virtcol(curwin);
update_curswant();
if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
|| curwin->w_curswant > curwin->w_virtcol)
@ -468,7 +468,7 @@ static int insert_check(VimState *state)
&& curwin->w_topline == s->old_topline
&& curwin->w_topfill == s->old_topfill) {
s->mincol = curwin->w_wcol;
validate_cursor_col();
validate_cursor_col(curwin);
if (curwin->w_wcol < s->mincol - tabstop_at(get_nolist_virtcol(),
curbuf->b_p_ts,
@ -478,7 +478,7 @@ static int insert_check(VimState *state)
|| curwin->w_topfill > 0)) {
if (curwin->w_topfill > 0) {
curwin->w_topfill--;
} else if (hasFolding(curwin->w_topline, NULL, &s->old_topline)) {
} else if (hasFolding(curwin, curwin->w_topline, NULL, &s->old_topline)) {
set_topline(curwin, s->old_topline + 1);
} else {
set_topline(curwin, curwin->w_topline + 1);
@ -491,7 +491,7 @@ static int insert_check(VimState *state)
s->did_backspace = false;
validate_cursor(); // may set must_redraw
validate_cursor(curwin); // may set must_redraw
// Redraw the display when no characters are waiting.
// Also shows mode, ruler and positions cursor.
@ -743,7 +743,7 @@ static int insert_handle_key(InsertState *s)
ins_ctrl_o();
// don't move the cursor left when 'virtualedit' has "onemore".
if (get_ve_flags() & VE_ONEMORE) {
if (get_ve_flags(curwin) & VE_ONEMORE) {
ins_at_eol = false;
s->nomove = true;
}
@ -1451,7 +1451,7 @@ void edit_putchar(int c, bool highlight)
int attr;
update_topline(curwin); // just in case w_topline isn't valid
validate_cursor();
validate_cursor(curwin);
if (highlight) {
attr = HL_ATTR(HLF_8);
} else {
@ -1521,7 +1521,7 @@ static void init_prompt(int cmdchar_todo)
ml_append(curbuf->b_ml.ml_line_count, prompt, 0, false);
}
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
inserted_bytes(curbuf->b_ml.ml_line_count, 0, 0, (colnr_T)strlen(prompt));
}
@ -1536,13 +1536,13 @@ static void init_prompt(int cmdchar_todo)
}
if (cmdchar_todo == 'A') {
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
}
if (curwin->w_cursor.col < (colnr_T)strlen(prompt)) {
curwin->w_cursor.col = (colnr_T)strlen(prompt);
}
// Make sure the cursor is in a valid position.
check_cursor();
check_cursor(curwin);
}
/// @return true if the cursor is in the editable position of the prompt line.
@ -2394,7 +2394,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove)
pos_T tpos = curwin->w_cursor;
curwin->w_cursor = *end_insert_pos;
check_cursor_col(); // make sure it is not past the line
check_cursor_col(curwin); // make sure it is not past the line
while (true) {
if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) {
curwin->w_cursor.col--;
@ -2471,7 +2471,7 @@ void free_last_insert(void)
void beginline(int flags)
{
if ((flags & BL_SOL) && !p_sol) {
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
} else {
curwin->w_cursor.col = 0;
curwin->w_cursor.coladd = 0;
@ -2497,13 +2497,13 @@ int oneright(void)
{
char *ptr;
if (virtual_active()) {
if (virtual_active(curwin)) {
pos_T prevpos = curwin->w_cursor;
// Adjust for multi-wide char (excluding TAB)
ptr = get_cursor_pos_ptr();
coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)))
? ptr2cells(ptr) : 1));
coladvance(curwin, getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)))
? ptr2cells(ptr) : 1));
curwin->w_set_curswant = true;
// Return OK if the cursor moved, FAIL otherwise (at window edge).
return (prevpos.col != curwin->w_cursor.col
@ -2519,7 +2519,7 @@ int oneright(void)
// move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
// contains "onemore".
if (ptr[l] == NUL && (get_ve_flags() & VE_ONEMORE) == 0) {
if (ptr[l] == NUL && (get_ve_flags(curwin) & VE_ONEMORE) == 0) {
return FAIL;
}
curwin->w_cursor.col += l;
@ -2531,7 +2531,7 @@ int oneright(void)
int oneleft(void)
{
if (virtual_active()) {
if (virtual_active(curwin)) {
int v = getviscol();
if (v == 0) {
@ -2541,7 +2541,7 @@ int oneleft(void)
// We might get stuck on 'showbreak', skip over it.
int width = 1;
while (true) {
coladvance(v - width);
coladvance(curwin, v - width);
// getviscol() is slow, skip it when 'showbreak' is empty,
// 'breakindent' is not set and there are no multi-byte
// characters
@ -2590,7 +2590,7 @@ void cursor_up_inner(win_T *wp, linenr_T n)
// Count each sequence of folded lines as one logical line.
// go to the start of the current fold
hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
hasFolding(wp, lnum, &lnum, NULL);
while (n--) {
// move up one line
@ -2602,7 +2602,7 @@ void cursor_up_inner(win_T *wp, linenr_T n)
// Insert mode or when 'foldopen' contains "all": it will open
// in a moment.
if (n > 0 || !((State & MODE_INSERT) || (fdo_flags & FDO_ALL))) {
hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
hasFolding(wp, lnum, &lnum, NULL);
}
}
if (lnum < 1) {
@ -2625,7 +2625,7 @@ int cursor_up(linenr_T n, bool upd_topline)
cursor_up_inner(curwin, n);
// try to advance to the column we want to be at
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
if (upd_topline) {
update_topline(curwin); // make sure curwin->w_topline is valid
@ -2678,7 +2678,7 @@ int cursor_down(int n, bool upd_topline)
cursor_down_inner(curwin, n);
// try to advance to the column we want to be at
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
if (upd_topline) {
update_topline(curwin); // make sure curwin->w_topline is valid
@ -3274,7 +3274,7 @@ static void ins_reg(void)
// Cursor may be moved back a column.
curwin->w_cursor = curpos;
check_cursor();
check_cursor(curwin);
}
if (regname == NUL || !valid_yank_reg(regname, false)) {
vim_beep(BO_REG);
@ -3466,7 +3466,7 @@ static bool ins_esc(int *count, int cmdchar, bool nomove)
&& (curwin->w_cursor.col != 0 || curwin->w_cursor.coladd > 0)
&& (restart_edit == NUL || (gchar_cursor() == NUL && !VIsual_active))
&& !revins_on) {
if (curwin->w_cursor.coladd > 0 || get_ve_flags() == VE_ALL) {
if (curwin->w_cursor.coladd > 0 || get_ve_flags(curwin) == VE_ALL) {
oneleft();
if (restart_edit != NUL) {
curwin->w_cursor.coladd++;
@ -3598,7 +3598,7 @@ static void ins_ctrl_o(void)
} else {
restart_edit = 'I';
}
if (virtual_active()) {
if (virtual_active(curwin)) {
ins_at_eol = false; // cursor always keeps its column
} else {
ins_at_eol = (gchar_cursor() == NUL);
@ -4028,7 +4028,7 @@ static void ins_left(void)
// always break undo when moving upwards/downwards, else undo may break
start_arrow(&tpos);
curwin->w_cursor.lnum--;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
curwin->w_set_curswant = true; // so we stay at the end
} else {
vim_beep(BO_CRSR);
@ -4062,7 +4062,7 @@ static void ins_end(int c)
if (c == K_C_END) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
curwin->w_curswant = MAXCOL;
start_arrow(&tpos);
@ -4096,13 +4096,13 @@ static void ins_right(void)
foldOpenCursor();
}
undisplay_dollar();
if (gchar_cursor() != NUL || virtual_active()) {
if (gchar_cursor() != NUL || virtual_active(curwin)) {
start_arrow_with_change(&curwin->w_cursor, end_change);
if (!end_change) {
AppendCharToRedobuff(K_RIGHT);
}
curwin->w_set_curswant = true;
if (virtual_active()) {
if (virtual_active(curwin)) {
oneright();
} else {
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
@ -4157,7 +4157,7 @@ static void ins_up(bool startcol)
pos_T tpos = curwin->w_cursor;
if (cursor_up(1, true) == OK) {
if (startcol) {
coladvance(getvcol_nolist(&Insstart));
coladvance(curwin, getvcol_nolist(&Insstart));
}
if (old_topline != curwin->w_topline
|| old_topfill != curwin->w_topfill) {
@ -4202,7 +4202,7 @@ static void ins_down(bool startcol)
pos_T tpos = curwin->w_cursor;
if (cursor_down(1, true) == OK) {
if (startcol) {
coladvance(getvcol_nolist(&Insstart));
coladvance(curwin, getvcol_nolist(&Insstart));
}
if (old_topline != curwin->w_topline
|| old_topfill != curwin->w_topfill) {
@ -4474,8 +4474,8 @@ bool ins_eol(int c)
// Put cursor on NUL if on the last char and coladd is 1 (happens after
// CTRL-O).
if (virtual_active() && curwin->w_cursor.coladd > 0) {
coladvance(getviscol());
if (virtual_active(curwin) && curwin->w_cursor.coladd > 0) {
coladvance(curwin, getviscol());
}
// NL in reverse insert will always start in the end of current line.
@ -4574,7 +4574,7 @@ int ins_copychar(linenr_T lnum)
}
// try to advance to the cursor column
validate_virtcol();
validate_virtcol(curwin);
int const end_vcol = curwin->w_virtcol;
char *line = ml_get(lnum);
@ -4720,7 +4720,7 @@ colnr_T get_nolist_virtcol(void)
if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL) {
return getvcol_nolist(&curwin->w_cursor);
}
validate_virtcol();
validate_virtcol(curwin);
return curwin->w_virtcol;
}

View File

@ -197,7 +197,7 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, typval_
&& ml_replace(lnum, line, true) == OK) {
inserted_bytes(lnum, 0, old_len, (int)strlen(line));
if (is_curbuf && lnum == curwin->w_cursor.lnum) {
check_cursor_col();
check_cursor_col(curwin);
}
rettv->vval.v_number = 0; // OK
}
@ -229,7 +229,7 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, typval_
wp->w_cursor.lnum += (linenr_T)added;
}
}
check_cursor_col();
check_cursor_col(curwin);
update_topline(curwin);
}
@ -469,7 +469,7 @@ void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
}
}
check_cursor_col();
check_cursor_col(curwin);
deleted_lines_mark(first, count);
rettv->vval.v_number = 0; // OK

View File

@ -727,7 +727,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol)
return;
}
check_cursor();
check_cursor(curwin);
winchanged = true;
}
@ -746,7 +746,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol)
col = fp->col + 1;
// col(".") when the cursor is on the NUL at the end of the line
// because of "coladd" can be seen as an extra column.
if (virtual_active() && fp == &curwin->w_cursor) {
if (virtual_active(curwin) && fp == &curwin->w_cursor) {
char *p = get_cursor_pos_ptr();
if (curwin->w_cursor.coladd >=
(colnr_T)win_chartabsize(curwin, p,
@ -1191,7 +1191,7 @@ static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol)
curwin->w_cursor.coladd = coladd;
// Make sure the cursor is in a valid position.
check_cursor();
check_cursor(curwin);
// Correct cursor for multi-byte character.
mb_adjust_cursor();
@ -2890,7 +2890,7 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
curbuf = findbuf;
curwin->w_buffer = curbuf;
const TriState save_virtual = virtual_op;
virtual_op = virtual_active();
virtual_op = virtual_active(curwin);
// NOTE: Adjust is needed.
p1.col--;
@ -4643,7 +4643,7 @@ static void f_line(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
if (wp != NULL && tp != NULL) {
switchwin_T switchwin;
if (switch_win_noblock(&switchwin, wp, tp, true) == OK) {
check_cursor();
check_cursor(curwin);
fp = var2fpos(&argvars[0], true, &fnum, false);
}
restore_win_noblock(&switchwin, true);
@ -7029,7 +7029,7 @@ static int search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
}
// "/$" will put the cursor after the end of the line, may need to
// correct that here
check_cursor();
check_cursor(curwin);
}
// If 'n' flag is used: restore cursor position.
@ -7791,7 +7791,7 @@ static void set_position(typval_T *argvars, typval_T *rettv, bool charpos)
curwin->w_curswant = curswant - 1;
curwin->w_set_curswant = false;
}
check_cursor();
check_cursor(curwin);
rettv->vval.v_number = 0;
} else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) {
// set mark
@ -9204,7 +9204,7 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
goto theend;
}
check_cursor();
check_cursor(curwin);
winchanged = true;
}

View File

@ -516,7 +516,7 @@ bool win_execute_before(win_execute_T *args, win_T *wp, tabpage_T *tp)
}
if (switch_win_noblock(&args->switchwin, wp, tp, true) == OK) {
check_cursor();
check_cursor(curwin);
return true;
}
return false;
@ -540,7 +540,7 @@ void win_execute_after(win_execute_T *args)
// In case the command moved the cursor or changed the Visual area,
// check it is valid.
check_cursor();
check_cursor(curwin);
if (VIsual_active) {
check_pos(curbuf, &VIsual);
}
@ -774,7 +774,7 @@ void f_winbufnr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "wincol()" function
void f_wincol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
validate_cursor();
validate_cursor(curwin);
rettv->vval.v_number = curwin->w_wcol + 1;
}
@ -811,7 +811,7 @@ void f_winlayout(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "winline()" function
void f_winline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
validate_cursor();
validate_cursor(curwin);
rettv->vval.v_number = curwin->w_wrow + 1;
}
@ -883,10 +883,10 @@ void f_winrestview(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
curwin->w_skipcol = (colnr_T)tv_get_number(&di->di_tv);
}
check_cursor();
check_cursor(curwin);
win_new_height(curwin, curwin->w_height);
win_new_width(curwin, curwin->w_width);
changed_window_setting();
changed_window_setting(curwin);
if (curwin->w_topline <= 0) {
curwin->w_topline = 1;

View File

@ -2638,14 +2638,14 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
if (newcol >= 0) { // position set by autocommands
curwin->w_cursor.lnum = newlnum;
curwin->w_cursor.col = newcol;
check_cursor();
check_cursor(curwin);
} else if (newlnum > 0) { // line number from caller or old position
curwin->w_cursor.lnum = newlnum;
check_cursor_lnum(curwin);
if (solcol >= 0 && !p_sol) {
// 'sol' is off: Use last known column.
curwin->w_cursor.col = solcol;
check_cursor_col();
check_cursor_col(curwin);
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
} else {
@ -3787,7 +3787,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n
highlight_match = true;
update_topline(curwin);
validate_cursor();
validate_cursor(curwin);
redraw_later(curwin, UPD_SOME_VALID);
show_cursor_info_later(true);
update_screen();
@ -4247,7 +4247,7 @@ skip:
// when interactive leave cursor on the match
if (!subflags.do_ask) {
if (endcolumn) {
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
} else {
beginline(BL_WHITE | BL_FIX);
}
@ -4278,7 +4278,7 @@ skip:
if (subflags.do_ask && hasAnyFolding(curwin)) {
// Cursor position may require updating
changed_window_setting();
changed_window_setting(curwin);
}
vim_regfree(regmatch.regprog);
@ -4514,7 +4514,7 @@ void global_exe(char *cmd)
if (global_need_beginline) {
beginline(BL_WHITE | BL_FIX);
} else {
check_cursor(); // cursor may be beyond the end of the line
check_cursor(curwin); // cursor may be beyond the end of the line
}
// the cursor may not have moved in the text but a change in a previous

View File

@ -654,7 +654,7 @@ void ex_listdo(exarg_T *eap)
}
if (eap->cmdidx == CMD_windo && execute) {
validate_cursor(); // cursor may have moved
validate_cursor(curwin); // cursor may have moved
// required when 'scrollbind' has been set
if (curwin->w_p_scb) {
do_check_scrollbind(true);

View File

@ -1743,8 +1743,8 @@ int execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo, bool preview)
&& eap->addr_type == ADDR_LINES) {
// Put the first line at the start of a closed fold, put the last line
// at the end of a closed fold.
hasFolding(eap->line1, &eap->line1, NULL);
hasFolding(eap->line2, NULL, &eap->line2);
hasFolding(curwin, eap->line1, &eap->line1, NULL);
hasFolding(curwin, eap->line2, NULL, &eap->line2);
}
// Use first argument as count when possible
@ -2213,8 +2213,8 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
&& ea.addr_type == ADDR_LINES) {
// Put the first line at the start of a closed fold, put the last line
// at the end of a closed fold.
hasFolding(ea.line1, &ea.line1, NULL);
hasFolding(ea.line2, NULL, &ea.line2);
hasFolding(curwin, ea.line1, &ea.line1, NULL);
hasFolding(curwin, ea.line2, NULL, &ea.line2);
}
// For the ":make" and ":grep" commands we insert the 'makeprg'/'grepprg'
@ -2875,9 +2875,9 @@ int parse_cmd_address(exarg_T *eap, const char **errormsg, bool silent)
// (where zero usually means to use the first line).
// Check the cursor position before returning.
if (eap->line2 > 0) {
check_cursor();
check_cursor(curwin);
} else {
check_cursor_col();
check_cursor_col(curwin);
}
need_check_cursor = true;
}
@ -2899,7 +2899,7 @@ int parse_cmd_address(exarg_T *eap, const char **errormsg, bool silent)
theend:
if (need_check_cursor) {
check_cursor();
check_cursor(curwin);
}
return ret;
}
@ -3596,7 +3596,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, bool
// closed fold after the first address.
if (addr_type == ADDR_LINES && (i == '-' || i == '+')
&& address_count >= 2) {
hasFolding(lnum, NULL, &lnum);
hasFolding(curwin, lnum, NULL, &lnum);
}
if (i == '-') {
lnum -= n;
@ -5528,8 +5528,6 @@ static void ex_swapname(exarg_T *eap)
/// (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
static void ex_syncbind(exarg_T *eap)
{
win_T *save_curwin = curwin;
buf_T *save_curbuf = curbuf;
linenr_T topline;
int y;
linenr_T old_linenr = curwin->w_cursor.lnum;
@ -5556,23 +5554,19 @@ static void ex_syncbind(exarg_T *eap)
// Set all scrollbind windows to the same topline.
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
if (curwin->w_p_scb) {
curbuf = curwin->w_buffer;
y = topline - curwin->w_topline;
if (wp->w_p_scb) {
y = topline - wp->w_topline;
if (y > 0) {
scrollup(y, true);
scrollup(wp, y, true);
} else {
scrolldown(-y, true);
scrolldown(wp, -y, true);
}
curwin->w_scbind_pos = topline;
redraw_later(curwin, UPD_VALID);
cursor_correct();
curwin->w_redr_status = true;
wp->w_scbind_pos = topline;
redraw_later(wp, UPD_VALID);
cursor_correct(wp);
wp->w_redr_status = true;
}
}
curwin = save_curwin;
curbuf = save_curbuf;
if (curwin->w_p_scb) {
did_syncbind = true;
checkpcmark();
@ -5854,7 +5848,7 @@ static void ex_equal(exarg_T *eap)
static void ex_sleep(exarg_T *eap)
{
if (cursor_valid()) {
if (cursor_valid(curwin)) {
setcursor_mayforce(true);
}
@ -5990,7 +5984,7 @@ static void ex_put(exarg_T *eap)
eap->forceit = true;
}
curwin->w_cursor.lnum = eap->line2;
check_cursor_col();
check_cursor_col(curwin);
do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1,
PUT_LINE|PUT_CURSLINE);
}
@ -6084,7 +6078,7 @@ static void ex_at(exarg_T *eap)
int prev_len = typebuf.tb_len;
curwin->w_cursor.lnum = eap->line2;
check_cursor_col();
check_cursor_col(curwin);
// Get the register name. No name means use the previous one.
int c = (uint8_t)(*eap->arg);
@ -6306,7 +6300,7 @@ static void ex_redraw(exarg_T *eap)
RedrawingDisabled = 0;
p_lz = false;
validate_cursor();
validate_cursor(curwin);
update_topline(curwin);
if (eap->forceit) {
redraw_all_later(UPD_NOT_VALID);
@ -6459,10 +6453,10 @@ static void ex_mark(exarg_T *eap)
/// Update w_topline, w_leftcol and the cursor position.
void update_topline_cursor(void)
{
check_cursor(); // put cursor on valid line
check_cursor(curwin); // put cursor on valid line
update_topline(curwin);
if (!curwin->w_p_wrap) {
validate_cursor();
validate_cursor(curwin);
}
update_curswant();
}
@ -6766,7 +6760,7 @@ static void ex_pedit(exarg_T *eap)
if (curwin != curwin_save && win_valid(curwin_save)) {
// Return cursor to where we were
validate_cursor();
validate_cursor(curwin);
redraw_later(curwin, UPD_VALID);
win_enter(curwin_save, true);
}
@ -7408,7 +7402,7 @@ static void ex_folddo(exarg_T *eap)
{
// First set the marks for all lines closed/open.
for (linenr_T lnum = eap->line1; lnum <= eap->line2; lnum++) {
if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) {
if (hasFolding(curwin, lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) {
ml_setmarked(lnum);
}
}

View File

@ -510,7 +510,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
s->match_start = curwin->w_cursor;
set_search_match(&curwin->w_cursor);
validate_cursor();
validate_cursor(curwin);
end_pos = curwin->w_cursor;
s->match_end = end_pos;
curwin->w_cursor = save_pos;
@ -530,7 +530,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
ccline.cmdbuff[skiplen + patlen] = next_char;
}
validate_cursor();
validate_cursor(curwin);
// May redraw the status line to show the cursor position.
if (p_ru && (curwin->w_status_height > 0 || global_stl_height() > 0)) {
@ -626,7 +626,7 @@ static void finish_incsearch_highlighting(bool gotesc, incsearch_state_T *s,
magic_overruled = s->magic_overruled_save;
validate_cursor(); // needed for TAB
validate_cursor(curwin); // needed for TAB
status_redraw_all();
redraw_all_later(UPD_SOME_VALID);
if (call_update_screen) {
@ -1483,7 +1483,7 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s
curwin->w_cursor = s->match_start;
changed_cline_bef_curs(curwin);
update_topline(curwin);
validate_cursor();
validate_cursor(curwin);
highlight_match = true;
save_viewstate(curwin, &s->old_viewstate);
redraw_later(curwin, UPD_NOT_VALID);
@ -4623,6 +4623,6 @@ static void set_search_match(pos_T *t)
t->col = search_match_endcol;
if (t->lnum > curbuf->b_ml.ml_line_count) {
t->lnum = curbuf->b_ml.ml_line_count;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
}
}

View File

@ -3197,7 +3197,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
curwin->w_topline = old_topline;
}
curwin->w_cursor = old_cursor;
check_cursor();
check_cursor(curwin);
update_topline(curwin);
keep_filetype = false;

View File

@ -143,7 +143,7 @@ void copyFoldingState(win_T *wp_from, win_T *wp_to)
}
// hasAnyFolding() {{{2
/// @return true if there may be folded lines in the current window.
/// @return true if there may be folded lines in window "win".
int hasAnyFolding(win_T *win)
{
// very simple now, but can become more complex later
@ -155,10 +155,10 @@ int hasAnyFolding(win_T *win)
/// When returning true, *firstp and *lastp are set to the first and last
/// lnum of the sequence of folded lines (skipped when NULL).
///
/// @return true if line "lnum" in the current window is part of a closed fold.
bool hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp)
/// @return true if line "lnum" in window "win" is part of a closed fold.
bool hasFolding(win_T *win, linenr_T lnum, linenr_T *firstp, linenr_T *lastp)
{
return hasFoldingWin(curwin, lnum, firstp, lastp, true, NULL);
return hasFoldingWin(win, lnum, firstp, lastp, true, NULL);
}
// hasFoldingWin() {{{2
@ -398,13 +398,13 @@ void opFoldRange(pos_T firstpos, pos_T lastpos, int opening, int recurse, bool h
// Opening one level only: next fold to open is after the one going to
// be opened.
if (opening && !recurse) {
hasFolding(lnum, NULL, &lnum_next);
hasFolding(curwin, lnum, NULL, &lnum_next);
}
setManualFold(temp, opening, recurse, &done);
// Closing one level only: next line to close a fold is after just
// closed fold.
if (!opening && !recurse) {
hasFolding(lnum, NULL, &lnum_next);
hasFolding(curwin, lnum, NULL, &lnum_next);
}
}
if (done == DONE_NOTHING) {
@ -477,7 +477,7 @@ static void newFoldLevelWin(win_T *wp)
}
wp->w_fold_manual = false;
}
changed_window_setting_win(wp);
changed_window_setting(wp);
}
// foldCheckClose() {{{2
@ -492,7 +492,7 @@ void foldCheckClose(void)
checkupdate(curwin);
if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum,
(int)curwin->w_p_fdl)) {
changed_window_setting();
changed_window_setting(curwin);
}
}
@ -661,7 +661,7 @@ void foldCreate(win_T *wp, pos_T start, pos_T end)
fp->fd_small = kNone;
// redraw
changed_window_setting_win(wp);
changed_window_setting(wp);
}
}
@ -735,7 +735,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const
did_one = true;
// redraw window
changed_window_setting_win(wp);
changed_window_setting(wp);
}
}
if (!did_one) {
@ -746,7 +746,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const
}
} else {
// Deleting markers may make cursor column invalid
check_cursor_col_win(wp);
check_cursor_col(wp);
}
if (last_lnum > 0) {
@ -1009,11 +1009,11 @@ void foldAdjustVisual(void)
start = &curwin->w_cursor;
end = &VIsual;
}
if (hasFolding(start->lnum, &start->lnum, NULL)) {
if (hasFolding(curwin, start->lnum, &start->lnum, NULL)) {
start->col = 0;
}
if (!hasFolding(end->lnum, NULL, &end->lnum)) {
if (!hasFolding(curwin, end->lnum, NULL, &end->lnum)) {
return;
}
@ -1028,9 +1028,9 @@ void foldAdjustVisual(void)
// cursor_foldstart() {{{2
/// Move the cursor to the first line of a closed fold.
void foldAdjustCursor(void)
void foldAdjustCursor(win_T *wp)
{
hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL);
hasFolding(wp, wp->w_cursor.lnum, &wp->w_cursor.lnum, NULL);
}
// Internal functions for "fold_T" {{{1
@ -1269,7 +1269,7 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, bool opening, bool re
}
wp->w_fold_manual = true;
if (done & DONE_ACTION) {
changed_window_setting_win(wp);
changed_window_setting(wp);
}
done |= DONE_FOLD;
} else if (donep == NULL && wp == curwin) {
@ -2117,7 +2117,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
// If some fold changed, need to redraw and position cursor.
if (fold_changed && wp->w_p_fen) {
changed_window_setting_win(wp);
changed_window_setting(wp);
}
// If we updated folds past "bot", need to redraw more lines. Don't do

View File

@ -2508,7 +2508,7 @@ static int vgetorpeek(bool advance)
unshowmode(true);
mode_deleted = true;
}
validate_cursor();
validate_cursor(curwin);
int old_wcol = curwin->w_wcol;
int old_wrow = curwin->w_wrow;
@ -2541,7 +2541,7 @@ static int vgetorpeek(bool advance)
curwin->w_wrow = curwin->w_cline_row
+ curwin->w_wcol / curwin->w_width_inner;
curwin->w_wcol %= curwin->w_width_inner;
curwin->w_wcol += curwin_col_off();
curwin->w_wcol += win_col_off(curwin);
col = 0; // no correction needed
} else {
curwin->w_wcol--;

View File

@ -1116,7 +1116,7 @@ void ex_retab(exarg_T *eap)
}
xfree(new_ts_str);
}
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
u_clearline(curbuf);
}
@ -1160,7 +1160,7 @@ int get_expr_indent(void)
curwin->w_cursor = save_pos;
curwin->w_curswant = save_curswant;
curwin->w_set_curswant = save_set_curswant;
check_cursor();
check_cursor(curwin);
State = save_State;
// Reset did_throw, unless 'debug' has "throw" and inside a try/catch.

View File

@ -2436,7 +2436,7 @@ static void expand_by_function(int type, char *base)
textlock--;
curwin->w_cursor = pos; // restore the cursor position
validate_cursor();
validate_cursor(curwin);
if (!equalpos(curwin->w_cursor, pos)) {
emsg(_(e_compldel));
goto theend;
@ -4096,7 +4096,7 @@ static int get_userdefined_compl_info(colnr_T curs_col)
State = save_State;
curwin->w_cursor = pos; // restore the cursor position
validate_cursor();
validate_cursor(curwin);
if (!equalpos(curwin->w_cursor, pos)) {
emsg(_(e_compldel));
return FAIL;

View File

@ -1797,7 +1797,7 @@ void ex_luado(exarg_T *const eap)
}
lua_pop(lstate, 1);
check_cursor();
check_cursor(curwin);
redraw_curbuf_later(UPD_NOT_VALID);
}

View File

@ -588,7 +588,7 @@ MarkMoveRes mark_move_to(fmark_T *fm, MarkMove flags)
}
if (res & kMarkSwitchedBuf || res & kMarkChangedCursor) {
check_cursor();
check_cursor(curwin);
}
end:
return res;

View File

@ -533,7 +533,7 @@ void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum)
for (shl->first_lnum = lnum;
shl->first_lnum > wp->w_topline;
shl->first_lnum--) {
if (hasFoldingWin(wp, shl->first_lnum - 1, NULL, NULL, true, NULL)) {
if (hasFolding(wp, shl->first_lnum - 1, NULL, NULL)) {
break;
}
}

View File

@ -1192,7 +1192,7 @@ void ml_recover(bool checkext)
ml_delete(curbuf->b_ml.ml_line_count, false);
}
curbuf->b_flags |= BF_RECOVERED;
check_cursor();
check_cursor(curwin);
recoverymode = false;
if (got_int) {
@ -4076,14 +4076,14 @@ void goto_byte(int cnt)
if (lnum < 1) { // past the end
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
curwin->w_curswant = MAXCOL;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
} else {
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = (colnr_T)boff;
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
}
check_cursor();
check_cursor(curwin);
// Make sure the cursor is on the first byte of a multi-byte char.
mb_adjust_cursor();

View File

@ -1478,11 +1478,11 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx)
// Activate visual mode
VIsual_active = true;
VIsual_reselect = true;
check_cursor();
check_cursor(curwin);
VIsual = curwin->w_cursor;
curwin->w_cursor = tpos;
check_cursor();
check_cursor(curwin);
// Adjust the cursor to make sure it is in the correct pos
// for exclusive mode

View File

@ -771,7 +771,7 @@ popupexit:
// move VIsual to the right column
start_visual = curwin->w_cursor; // save the cursor pos
curwin->w_cursor = end_visual;
coladvance(end_visual.col);
coladvance(curwin, end_visual.col);
VIsual = curwin->w_cursor;
curwin->w_cursor = start_visual; // restore the cursor
} else {
@ -1430,7 +1430,7 @@ retnomove:
break;
}
first = false;
hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL);
if (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline)) {
curwin->w_topfill++;
} else {
@ -1460,7 +1460,7 @@ retnomove:
if (curwin->w_topfill > 0) {
curwin->w_topfill--;
} else {
if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline)
if (hasFolding(curwin, curwin->w_topline, NULL, &curwin->w_topline)
&& curwin->w_topline == curbuf->b_ml.ml_line_count) {
break;
}
@ -1515,7 +1515,7 @@ retnomove:
curwin->w_curswant = col;
curwin->w_set_curswant = false; // May still have been true
if (coladvance(col) == FAIL) { // Mouse click beyond end of line
if (coladvance(curwin, col) == FAIL) { // Mouse click beyond end of line
if (inclusive != NULL) {
*inclusive = true;
}
@ -1548,7 +1548,7 @@ static bool do_mousescroll_horiz(colnr_T leftcol)
// When the line of the cursor is too short, move the cursor to the
// longest visible line.
if (!virtual_active()
if (!virtual_active(curwin)
&& leftcol > scroll_line_len(curwin->w_cursor.lnum)) {
curwin->w_cursor.lnum = find_longest_lnum();
curwin->w_cursor.col = 0;
@ -1637,7 +1637,7 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
break; // Position is in this buffer line.
}
hasFoldingWin(win, lnum, NULL, &lnum, true, NULL);
hasFolding(win, lnum, NULL, &lnum);
if (lnum == win->w_buffer->b_ml.ml_line_count) {
retval = true;

File diff suppressed because it is too large Load Diff

View File

@ -1009,12 +1009,12 @@ normal_end:
mb_check_adjust_col(curwin); // #6203
if (curwin->w_p_scb && s->toplevel) {
validate_cursor(); // may need to update w_leftcol
validate_cursor(curwin); // may need to update w_leftcol
do_check_scrollbind(true);
}
if (curwin->w_p_crb && s->toplevel) {
validate_cursor(); // may need to update w_leftcol
validate_cursor(curwin); // may need to update w_leftcol
do_check_cursorbind();
}
@ -1343,7 +1343,7 @@ static void normal_redraw(NormalState *s)
// Before redrawing, make sure w_topline is correct, and w_leftcol
// if lines don't wrap, and w_skipcol if lines wrap.
update_topline(curwin);
validate_cursor();
validate_cursor(curwin);
show_cursor_info_later(false);
@ -1420,7 +1420,7 @@ static int normal_check(VimState *state)
// Ensure curwin->w_topline and curwin->w_leftcol are up to date
// before triggering a WinScrolled autocommand.
update_topline(curwin);
validate_cursor();
validate_cursor(curwin);
normal_check_cursor_moved(s);
normal_check_text_changed(s);
@ -1515,7 +1515,7 @@ void end_visual_mode(void)
curbuf->b_visual.vi_end = curwin->w_cursor;
curbuf->b_visual.vi_curswant = curwin->w_curswant;
curbuf->b_visual_mode_eval = VIsual_mode;
if (!virtual_active()) {
if (!virtual_active(curwin)) {
curwin->w_cursor.coladd = 0;
}
@ -1863,8 +1863,8 @@ void clear_showcmd(void)
bot = VIsual.lnum;
}
// Include closed folds as a whole.
hasFolding(top, &top, NULL);
hasFolding(bot, NULL, &bot);
hasFolding(curwin, top, &top, NULL);
hasFolding(curwin, bot, NULL, &bot);
lines = bot - top + 1;
if (VIsual_mode == Ctrl_V) {
@ -2174,14 +2174,14 @@ void check_scrollbind(linenr_T topline_diff, int leftcol_diff)
y = topline - curwin->w_topline;
if (y > 0) {
scrollup(y, false);
scrollup(curwin, y, false);
} else {
scrolldown(-y, false);
scrolldown(curwin, -y, false);
}
}
redraw_later(curwin, UPD_VALID);
cursor_correct();
cursor_correct(curwin);
curwin->w_redr_status = true;
}
@ -2466,8 +2466,8 @@ static bool nv_screengo(oparg_T *oap, int dir, int dist)
oap->motion_type = kMTCharWise;
oap->inclusive = (curwin->w_curswant == MAXCOL);
col_off1 = curwin_col_off();
col_off2 = col_off1 - curwin_col_off2();
col_off1 = win_col_off(curwin);
col_off2 = col_off1 - win_col_off2(curwin);
width1 = curwin->w_width_inner - col_off1;
width2 = curwin->w_width_inner - col_off2;
@ -2481,7 +2481,7 @@ static bool nv_screengo(oparg_T *oap, int dir, int dist)
// try to stick in the last column of the screen.
if (curwin->w_curswant == MAXCOL) {
atend = true;
validate_virtcol();
validate_virtcol(curwin);
if (width1 <= 0) {
curwin->w_curswant = 0;
} else {
@ -2506,7 +2506,7 @@ static bool nv_screengo(oparg_T *oap, int dir, int dist)
while (dist--) {
if (dir == BACKWARD) {
if (curwin->w_curswant >= width1
&& !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
&& !hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
// Move back within the line. This can give a negative value
// for w_curswant if width1 < width2 (with cpoptions+=n),
// which will get clipped to column 0.
@ -2533,7 +2533,7 @@ static bool nv_screengo(oparg_T *oap, int dir, int dist)
n = width1;
}
if (curwin->w_curswant + width2 < (colnr_T)n
&& !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
&& !hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
// move forward within line
curwin->w_curswant += width2;
} else {
@ -2558,17 +2558,17 @@ static bool nv_screengo(oparg_T *oap, int dir, int dist)
}
}
if (virtual_active() && atend) {
coladvance(MAXCOL);
if (virtual_active(curwin) && atend) {
coladvance(curwin, MAXCOL);
} else {
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
}
if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) {
// Check for landing on a character that got split at the end of the
// last line. We want to advance a screenline, not end up in the same
// screenline or move two screenlines.
validate_virtcol();
validate_virtcol(curwin);
colnr_T virtcol = curwin->w_virtcol;
if (virtcol > (colnr_T)width1 && *get_showbreak_value(curwin) != NUL) {
virtcol -= vim_strsize(get_showbreak_value(curwin));
@ -2616,13 +2616,13 @@ void scroll_redraw(bool up, linenr_T count)
linenr_T prev_lnum = curwin->w_cursor.lnum;
bool moved = up
? scrollup(count, true)
: scrolldown(count, true);
? scrollup(curwin, count, true)
: scrolldown(curwin, count, true);
if (get_scrolloff_value(curwin) > 0) {
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
// valid, otherwise the screen jumps back at the end of the file.
cursor_correct();
cursor_correct(curwin);
check_cursor_moved(curwin);
curwin->w_valid |= VALID_TOPLINE;
@ -2651,7 +2651,7 @@ void scroll_redraw(bool up, linenr_T count)
}
}
if (curwin->w_cursor.lnum != prev_lnum) {
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
}
if (moved) {
curwin->w_viewport_invalid = true;
@ -2803,7 +2803,7 @@ static void nv_zet(cmdarg_T *cap)
} else {
curwin->w_cursor.lnum = cap->count0;
}
check_cursor_col();
check_cursor_col(curwin);
}
switch (nchar) {
@ -2826,7 +2826,7 @@ static void nv_zet(cmdarg_T *cap)
FALLTHROUGH;
case 't':
scroll_cursor_top(0, true);
scroll_cursor_top(curwin, 0, true);
redraw_later(curwin, UPD_VALID);
set_fraction(curwin);
break;
@ -2837,7 +2837,7 @@ static void nv_zet(cmdarg_T *cap)
FALLTHROUGH;
case 'z':
scroll_cursor_halfway(true, false);
scroll_cursor_halfway(curwin, true, false);
redraw_later(curwin, UPD_VALID);
set_fraction(curwin);
break;
@ -2847,7 +2847,7 @@ static void nv_zet(cmdarg_T *cap)
// when <count> is at bottom of window, and puts that one at
// bottom of window.
if (cap->count0 != 0) {
scroll_cursor_bot(0, true);
scroll_cursor_bot(curwin, 0, true);
curwin->w_cursor.lnum = curwin->w_topline;
} else if (curwin->w_topline == 1) {
curwin->w_cursor.lnum = 1;
@ -2860,7 +2860,7 @@ static void nv_zet(cmdarg_T *cap)
FALLTHROUGH;
case 'b':
scroll_cursor_bot(0, true);
scroll_cursor_bot(curwin, 0, true);
redraw_later(curwin, UPD_VALID);
set_fraction(curwin);
break;
@ -2895,7 +2895,7 @@ static void nv_zet(cmdarg_T *cap)
// "zs" - scroll screen, cursor at the start
case 's':
if (!curwin->w_p_wrap) {
if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
col = 0; // like the cursor is in col 0
} else {
getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
@ -2915,12 +2915,12 @@ static void nv_zet(cmdarg_T *cap)
// "ze" - scroll screen, cursor at the end
case 'e':
if (!curwin->w_p_wrap) {
if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
col = 0; // like the cursor is in col 0
} else {
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
}
int n = curwin->w_width_inner - curwin_col_off();
int n = curwin->w_width_inner - win_col_off(curwin);
if (col + siso < n) {
col = 0;
} else {
@ -2980,7 +2980,7 @@ static void nv_zet(cmdarg_T *cap)
case 'E':
if (foldmethodIsManual(curwin)) {
clearFolding(curwin);
changed_window_setting();
changed_window_setting(curwin);
} else if (foldmethodIsMarker(curwin)) {
deleteFold(curwin, 1, curbuf->b_ml.ml_line_count, true, false);
} else {
@ -3005,7 +3005,7 @@ static void nv_zet(cmdarg_T *cap)
// "za": open closed fold or close open fold at cursor
case 'a':
if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
openFold(curwin->w_cursor, cap->count1);
} else {
closeFold(curwin->w_cursor, cap->count1);
@ -3015,7 +3015,7 @@ static void nv_zet(cmdarg_T *cap)
// "zA": open fold at cursor recursively
case 'A':
if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, NULL)) {
openFoldRecurse(curwin->w_cursor);
} else {
closeFoldRecurse(curwin->w_cursor);
@ -3151,11 +3151,11 @@ static void nv_zet(cmdarg_T *cap)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
wp->w_p_fen = curwin->w_p_fen;
changed_window_setting_win(wp);
changed_window_setting(wp);
}
}
}
changed_window_setting();
changed_window_setting(curwin);
}
// Redraw when 'foldlevel' changed.
@ -3639,7 +3639,7 @@ static void nv_scroll(cmdarg_T *cap)
// Count a fold for one screen line.
for (n = cap->count1 - 1; n > 0
&& curwin->w_cursor.lnum > curwin->w_topline; n--) {
hasFolding(curwin->w_cursor.lnum,
hasFolding(curwin, curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
if (curwin->w_cursor.lnum > curwin->w_topline) {
curwin->w_cursor.lnum--;
@ -3668,7 +3668,7 @@ static void nv_scroll(cmdarg_T *cap)
if (used >= half) {
break;
}
if (hasFolding(curwin->w_topline + n, NULL, &lnum)) {
if (hasFolding(curwin, curwin->w_topline + n, NULL, &lnum)) {
n = lnum - curwin->w_topline;
}
}
@ -3681,7 +3681,7 @@ static void nv_scroll(cmdarg_T *cap)
// Count a fold for one screen line.
lnum = curwin->w_topline;
while (n-- > 0 && lnum < curwin->w_botline - 1) {
hasFolding(lnum, NULL, &lnum);
hasFolding(curwin, lnum, NULL, &lnum);
lnum++;
}
n = lnum - curwin->w_topline;
@ -3695,7 +3695,7 @@ static void nv_scroll(cmdarg_T *cap)
// Correct for 'so', except when an operator is pending.
if (cap->oap->op_type == OP_NOP) {
cursor_correct();
cursor_correct(curwin);
}
beginline(BL_SOL | BL_FIX);
}
@ -3720,7 +3720,7 @@ static void nv_right(cmdarg_T *cap)
// In virtual edit mode, there's no such thing as "past_line", as lines
// are (theoretically) infinitely long.
if (virtual_active()) {
if (virtual_active(curwin)) {
past_line = false;
}
@ -3763,7 +3763,7 @@ static void nv_right(cmdarg_T *cap)
break;
} else if (past_line) {
curwin->w_set_curswant = true;
if (virtual_active()) {
if (virtual_active(curwin)) {
oneright();
} else {
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
@ -3805,7 +3805,7 @@ static void nv_left(cmdarg_T *cap)
|| (cap->cmdchar == K_LEFT && vim_strchr(p_ww, '<') != NULL))
&& curwin->w_cursor.lnum > 1) {
curwin->w_cursor.lnum--;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
curwin->w_set_curswant = true;
// When the NL before the first char has to be deleted we
@ -3940,7 +3940,7 @@ static void nv_dollar(cmdarg_T *cap)
// In virtual mode when off the edge of a line and an operator
// is pending (whew!) keep the cursor where it is.
// Otherwise, send it to the end of the line.
if (!virtual_active() || gchar_cursor() != NUL
if (!virtual_active(curwin) || gchar_cursor() != NUL
|| cap->oap->op_type == OP_NOP) {
curwin->w_curswant = MAXCOL; // so we stay at the end
}
@ -4034,7 +4034,7 @@ static int normal_search(cmdarg_T *cap, int dir, char *pat, int opt, int *wrappe
// "/$" will put the cursor after the end of the line, may need to
// correct that here
check_cursor();
check_cursor(curwin);
return i;
}
@ -4060,7 +4060,7 @@ static void nv_csearch(cmdarg_T *cap)
curwin->w_set_curswant = true;
// Include a Tab for "tx" and for "dfx".
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
if (gchar_cursor() == TAB && virtual_active(curwin) && cap->arg == FORWARD
&& (t_cmd || cap->oap->op_type != OP_NOP)) {
colnr_T scol, ecol;
@ -4516,7 +4516,7 @@ static void nv_replace(cmdarg_T *cap)
}
// Break tabs, etc.
if (virtual_active()) {
if (virtual_active(curwin)) {
if (u_save_cursor() == false) {
return;
}
@ -4628,7 +4628,7 @@ static void v_swap_corners(int cmdchar)
pos_T old_cursor = curwin->w_cursor;
getvcols(curwin, &old_cursor, &VIsual, &left, &right);
curwin->w_cursor.lnum = VIsual.lnum;
coladvance(left);
coladvance(curwin, left);
VIsual = curwin->w_cursor;
curwin->w_cursor.lnum = old_cursor.lnum;
@ -4638,20 +4638,20 @@ static void v_swap_corners(int cmdchar)
if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') {
curwin->w_curswant++;
}
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
if (curwin->w_cursor.col == old_cursor.col
&& (!virtual_active()
&& (!virtual_active(curwin)
|| curwin->w_cursor.coladd ==
old_cursor.coladd)) {
curwin->w_cursor.lnum = VIsual.lnum;
if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') {
right++;
}
coladvance(right);
coladvance(curwin, right);
VIsual = curwin->w_cursor;
curwin->w_cursor.lnum = old_cursor.lnum;
coladvance(left);
coladvance(curwin, left);
curwin->w_curswant = left;
}
} else {
@ -4681,8 +4681,8 @@ static void nv_Replace(cmdarg_T *cap)
if (!MODIFIABLE(curbuf)) {
emsg(_(e_modifiable));
} else {
if (virtual_active()) {
coladvance(getviscol());
if (virtual_active(curwin)) {
coladvance(curwin, getviscol());
}
invoke_edit(cap, false, cap->arg ? 'V' : 'R', false);
}
@ -4716,8 +4716,8 @@ static void nv_vreplace(cmdarg_T *cap)
}
stuffcharReadbuff(cap->extra_char);
stuffcharReadbuff(ESC);
if (virtual_active()) {
coladvance(getviscol());
if (virtual_active(curwin)) {
coladvance(curwin, getviscol());
}
invoke_edit(cap, true, 'v', false);
}
@ -4764,7 +4764,7 @@ static void n_swapchar(cmdarg_T *cap)
}
}
check_cursor();
check_cursor(curwin);
curwin->w_set_curswant = true;
if (did_change) {
changed_lines(curbuf, startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1,
@ -4896,7 +4896,7 @@ static void nv_gomark(cmdarg_T *cap)
move_res = nv_mark_move_to(cap, flags, fm);
// May need to clear the coladd that a mark includes.
if (!virtual_active()) {
if (!virtual_active(curwin)) {
curwin->w_cursor.coladd = 0;
}
@ -5025,7 +5025,7 @@ static void nv_visual(cmdarg_T *cap)
// was only one -- webb
if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) {
curwin->w_cursor.lnum += resel_VIsual_line_count * cap->count0 - 1;
check_cursor();
check_cursor(curwin);
}
VIsual_mode = resel_VIsual_mode;
if (VIsual_mode == 'v') {
@ -5039,11 +5039,11 @@ static void nv_visual(cmdarg_T *cap)
} else {
curwin->w_curswant = resel_VIsual_vcol;
}
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
}
if (resel_VIsual_vcol == MAXCOL) {
curwin->w_curswant = MAXCOL;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
} else if (VIsual_mode == Ctrl_V) {
// Update curswant on the original line, that is where "col" is valid.
linenr_T lnum = curwin->w_cursor.lnum;
@ -5052,7 +5052,7 @@ static void nv_visual(cmdarg_T *cap)
assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX);
curwin->w_curswant += resel_VIsual_vcol * cap->count0 - 1;
curwin->w_cursor.lnum = lnum;
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
} else {
curwin->w_set_curswant = true;
}
@ -5104,9 +5104,9 @@ static void n_start_visual_mode(int c)
// Corner case: the 0 position in a tab may change when going into
// virtualedit. Recalculate curwin->w_cursor to avoid bad highlighting.
//
if (c == Ctrl_V && (get_ve_flags() & VE_BLOCK) && gchar_cursor() == TAB) {
validate_virtcol();
coladvance(curwin->w_virtcol);
if (c == Ctrl_V && (get_ve_flags(curwin) & VE_BLOCK) && gchar_cursor() == TAB) {
validate_virtcol(curwin);
coladvance(curwin, curwin->w_virtcol);
}
VIsual = curwin->w_cursor;
@ -5194,10 +5194,10 @@ static void nv_gv_cmd(cmdarg_T *cap)
// Set Visual to the start and w_cursor to the end of the Visual
// area. Make sure they are on an existing character.
check_cursor();
check_cursor(curwin);
VIsual = curwin->w_cursor;
curwin->w_cursor = tpos;
check_cursor();
check_cursor(curwin);
update_topline(curwin);
// When called from normal "g" command: start Select mode when
@ -5224,10 +5224,10 @@ static void nv_g_home_m_cmd(cmdarg_T *cap)
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
if (curwin->w_p_wrap && curwin->w_width_inner != 0) {
int width1 = curwin->w_width_inner - curwin_col_off();
int width2 = width1 + curwin_col_off2();
int width1 = curwin->w_width_inner - win_col_off(curwin);
int width2 = width1 + win_col_off2(curwin);
validate_virtcol();
validate_virtcol(curwin);
i = 0;
if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) {
i = (curwin->w_virtcol - width1) / width2 * width2 + width1;
@ -5239,10 +5239,10 @@ static void nv_g_home_m_cmd(cmdarg_T *cap)
// 'relativenumber' is on and lines are wrapping the middle can be more
// to the left.
if (cap->nchar == 'm') {
i += (curwin->w_width_inner - curwin_col_off()
+ ((curwin->w_p_wrap && i > 0) ? curwin_col_off2() : 0)) / 2;
i += (curwin->w_width_inner - win_col_off(curwin)
+ ((curwin->w_p_wrap && i > 0) ? win_col_off2(curwin) : 0)) / 2;
}
coladvance((colnr_T)i);
coladvance(curwin, (colnr_T)i);
if (flag) {
do {
i = gchar_cursor();
@ -5284,7 +5284,7 @@ static void nv_g_dollar_cmd(cmdarg_T *cap)
{
oparg_T *oap = cap->oap;
int i;
int col_off = curwin_col_off();
int col_off = win_col_off(curwin);
const bool flag = cap->nchar == K_END || cap->nchar == K_KEND;
oap->motion_type = kMTCharWise;
@ -5293,14 +5293,14 @@ static void nv_g_dollar_cmd(cmdarg_T *cap)
curwin->w_curswant = MAXCOL; // so we stay at the end
if (cap->count1 == 1) {
int width1 = curwin->w_width_inner - col_off;
int width2 = width1 + curwin_col_off2();
int width2 = width1 + win_col_off2(curwin);
validate_virtcol();
validate_virtcol(curwin);
i = width1 - 1;
if (curwin->w_virtcol >= (colnr_T)width1) {
i += ((curwin->w_virtcol - width1) / width2 + 1) * width2;
}
coladvance((colnr_T)i);
coladvance(curwin, (colnr_T)i);
// Make sure we stick in this column.
update_curswant_force();
@ -5321,7 +5321,7 @@ static void nv_g_dollar_cmd(cmdarg_T *cap)
cursor_down(cap->count1 - 1, false);
}
i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1;
coladvance((colnr_T)i);
coladvance(curwin, (colnr_T)i);
// if the character doesn't fit move one back
if (curwin->w_cursor.col > 0 && utf_ptr2cells(get_cursor_pos_ptr()) > 1) {
@ -5352,7 +5352,7 @@ static void nv_gi_cmd(cmdarg_T *cap)
check_cursor_lnum(curwin);
int i = (int)get_cursor_line_len();
if (curwin->w_cursor.col > (colnr_T)i) {
if (virtual_active()) {
if (virtual_active(curwin)) {
curwin->w_cursor.coladd += curwin->w_cursor.col - i;
}
curwin->w_cursor.col = i;
@ -5480,9 +5480,9 @@ static void nv_g_cmd(cmdarg_T *cap)
oap->inclusive = false;
i = linetabsize(curwin, curwin->w_cursor.lnum);
if (cap->count0 > 0 && cap->count0 <= 100) {
coladvance((colnr_T)(i * cap->count0 / 100));
coladvance(curwin, (colnr_T)(i * cap->count0 / 100));
} else {
coladvance((colnr_T)(i / 2));
coladvance(curwin, (colnr_T)(i / 2));
}
curwin->w_set_curswant = true;
break;
@ -5705,11 +5705,11 @@ static void n_opencmd(cmdarg_T *cap)
if (cap->cmdchar == 'O') {
// Open above the first line of a folded sequence of lines
hasFolding(curwin->w_cursor.lnum,
hasFolding(curwin, curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
} else {
// Open below the last line of a folded sequence of lines
hasFolding(curwin->w_cursor.lnum,
hasFolding(curwin, curwin->w_cursor.lnum,
NULL, &curwin->w_cursor.lnum);
}
// trigger TextChangedI for the 'o/O' command
@ -5890,7 +5890,7 @@ static void nv_pipe(cmdarg_T *cap)
cap->oap->inclusive = false;
beginline(0);
if (cap->count0 > 0) {
coladvance((colnr_T)(cap->count0 - 1));
coladvance(curwin, (colnr_T)(cap->count0 - 1));
curwin->w_curswant = (colnr_T)(cap->count0 - 1);
} else {
curwin->w_curswant = 0;
@ -5986,8 +5986,8 @@ static void adjust_cursor(oparg_T *oap)
// - 'virtualedit' is not "all" and not "onemore".
if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
&& (!VIsual_active || *p_sel == 'o')
&& !virtual_active()
&& (get_ve_flags() & VE_ONEMORE) == 0) {
&& !virtual_active(curwin)
&& (get_ve_flags(curwin) & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
// prevent cursor from moving on the trail byte
mb_adjust_cursor();
@ -6150,7 +6150,7 @@ static void nv_esc(cmdarg_T *cap)
if (VIsual_active) {
end_visual_mode(); // stop Visual
check_cursor_col(); // make sure cursor is not beyond EOL
check_cursor_col(curwin); // make sure cursor is not beyond EOL
curwin->w_set_curswant = true;
redraw_curbuf_later(UPD_INVERTED);
} else if (no_reason) {
@ -6163,12 +6163,12 @@ static void nv_esc(cmdarg_T *cap)
void set_cursor_for_append_to_line(void)
{
curwin->w_set_curswant = true;
if (get_ve_flags() == VE_ALL) {
if (get_ve_flags(curwin) == VE_ALL) {
const int save_State = State;
// Pretend Insert mode here to allow the cursor on the
// character past the end of the line
State = MODE_INSERT;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
State = save_State;
} else {
curwin->w_cursor.col += (colnr_T)strlen(get_cursor_pos_ptr());
@ -6206,7 +6206,7 @@ static void nv_edit(cmdarg_T *cap)
case 'a': // "a"ppend is like "i"nsert on the next character.
// increment coladd when in virtual space, increment the
// column otherwise, also to append after an unprintable char
if (virtual_active()
if (virtual_active(curwin)
&& (curwin->w_cursor.coladd > 0
|| *get_cursor_pos_ptr() == NUL
|| *get_cursor_pos_ptr() == TAB)) {
@ -6223,7 +6223,7 @@ static void nv_edit(cmdarg_T *cap)
// Pretend Insert mode here to allow the cursor on the
// character past the end of the line
State = MODE_INSERT;
coladvance(getviscol());
coladvance(curwin, getviscol());
State = save_State;
}
@ -6578,7 +6578,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// line.
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
}
}
auto_format(false, true);

View File

@ -1587,7 +1587,7 @@ int op_delete(oparg_T *oap)
kExtmarkUndo);
}
check_cursor_col();
check_cursor_col(curwin);
changed_lines(curbuf, curwin->w_cursor.lnum, curwin->w_cursor.col,
oap->end.lnum + 1, 0, true);
oap->line_count = 0; // no lines deleted
@ -1637,7 +1637,7 @@ int op_delete(oparg_T *oap)
coladvance_force(getviscol2(oap->start.col, oap->start.coladd));
oap->start = curwin->w_cursor;
if (oap->line_count == 1) {
coladvance(endcol);
coladvance(curwin, endcol);
oap->end.col = curwin->w_cursor.col;
oap->end.coladd = curwin->w_cursor.coladd;
curwin->w_cursor = oap->start;
@ -1840,7 +1840,7 @@ static int op_replace(oparg_T *oap, int c)
pos_T vpos;
vpos.lnum = curwin->w_cursor.lnum;
getvpos(&vpos, oap->start_vcol);
getvpos(curwin, &vpos, oap->start_vcol);
bd.startspaces += vpos.coladd;
n = bd.startspaces;
} else {
@ -1975,7 +1975,7 @@ static int op_replace(oparg_T *oap, int c)
}
coladvance_force(getviscol());
if (curwin->w_cursor.lnum == oap->end.lnum) {
getvpos(&oap->end, end_vcol);
getvpos(curwin, &oap->end, end_vcol);
}
}
// with "coladd" set may move to just after a TAB
@ -2018,7 +2018,7 @@ static int op_replace(oparg_T *oap, int c)
}
curwin->w_cursor = oap->start;
check_cursor();
check_cursor(curwin);
changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0, true);
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
@ -2260,7 +2260,7 @@ void op_insert(oparg_T *oap, int count1)
}
} else {
curwin->w_cursor = oap->end;
check_cursor_col();
check_cursor_col(curwin);
// Works just like an 'i'nsert on the next character.
if (!LINEEMPTY(curwin->w_cursor.lnum)
@ -2393,7 +2393,7 @@ void op_insert(oparg_T *oap, int count1)
}
curwin->w_cursor.col = oap->start.col;
check_cursor();
check_cursor(curwin);
xfree(ins_text);
}
}
@ -2488,7 +2488,7 @@ int op_change(oparg_T *oap)
// initial coladd offset as part of "startspaces"
if (bd.is_short) {
vpos.lnum = linenr;
getvpos(&vpos, oap->start_vcol);
getvpos(curwin, &vpos, oap->start_vcol);
} else {
vpos.coladd = 0;
}
@ -2509,7 +2509,7 @@ int op_change(oparg_T *oap)
0, vpos.coladd + ins_len, kExtmarkUndo);
}
}
check_cursor();
check_cursor(curwin);
changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0, true);
xfree(ins_text);
}
@ -2843,7 +2843,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
bool allocated = false;
const pos_T orig_start = curbuf->b_op_start;
const pos_T orig_end = curbuf->b_op_end;
unsigned cur_ve_flags = get_ve_flags();
unsigned cur_ve_flags = get_ve_flags(curwin);
if (flags & PUT_FIXINDENT) {
orig_indent = get_indent();
@ -3064,9 +3064,9 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
// Correct line number for closed fold. Don't move the cursor yet,
// u_save() uses it.
if (dir == BACKWARD) {
hasFolding(lnum, &lnum, NULL);
hasFolding(curwin, lnum, &lnum, NULL);
} else {
hasFolding(lnum, NULL, &lnum);
hasFolding(curwin, lnum, NULL, &lnum);
}
if (dir == FORWARD) {
lnum++;
@ -3362,7 +3362,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
pos_T pos = {
.lnum = lnum,
};
if (getvpos(&pos, vcol) == OK) {
if (getvpos(curwin, &pos, vcol) == OK) {
col = pos.col;
} else {
col = MAXCOL;
@ -3616,7 +3616,7 @@ end:
/// there move it left.
void adjust_cursor_eol(void)
{
unsigned cur_ve_flags = get_ve_flags();
unsigned cur_ve_flags = get_ve_flags(curwin);
const bool adj_cursor = (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
@ -4078,7 +4078,7 @@ int do_join(size_t count, bool insert_space, bool save_undo, bool use_formatopti
// vim: use the column of the last join
curwin->w_cursor.col =
(vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col);
check_cursor_col();
check_cursor_col(curwin);
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
@ -4445,7 +4445,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
// "Unsigned"
const bool do_unsigned = vim_strchr(curbuf->b_p_nf, 'u') != NULL;
if (virtual_active()) {
if (virtual_active(curwin)) {
save_coladd = pos->coladd;
pos->coladd = 0;
}
@ -4767,7 +4767,7 @@ theend:
curwin->w_cursor = save_cursor;
} else if (did_change) {
curwin->w_set_curswant = true;
} else if (virtual_active()) {
} else if (virtual_active(curwin)) {
curwin->w_cursor.coladd = save_coladd;
}
@ -5349,7 +5349,7 @@ void cursor_pos_info(dict_T *dict)
switch (l_VIsual_mode) {
case Ctrl_V:
virtual_op = virtual_active();
virtual_op = virtual_active(curwin);
block_prep(&oparg, &bd, lnum, false);
virtual_op = kNone;
s = bd.textstart;
@ -5438,7 +5438,7 @@ void cursor_pos_info(dict_T *dict)
}
} else {
char *p = get_cursor_line_ptr();
validate_virtcol();
validate_virtcol(curwin);
col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1,
(int)curwin->w_virtcol + 1);
col_print(buf2, sizeof(buf2), (int)strlen(p), linetabsize_str(p));
@ -5523,7 +5523,7 @@ static void op_colon(oparg_T *oap)
// When using !! on a closed fold the range ".!" works best to operate
// on, it will be made the whole closed fold later.
linenr_T endOfStartFold = oap->start.lnum;
hasFolding(oap->start.lnum, NULL, &endOfStartFold);
hasFolding(curwin, oap->start.lnum, NULL, &endOfStartFold);
if (oap->end.lnum != oap->start.lnum && oap->end.lnum != endOfStartFold) {
// Make it a range with the end line.
stuffcharReadbuff(',');
@ -5534,7 +5534,7 @@ static void op_colon(oparg_T *oap)
} else if (oap->start.lnum == curwin->w_cursor.lnum
// do not use ".+number" for a closed fold, it would count
// folded lines twice
&& !hasFolding(oap->end.lnum, NULL, NULL)) {
&& !hasFolding(curwin, oap->end.lnum, NULL, NULL)) {
stuffReadbuff(".+");
stuffnumReadbuff(oap->line_count - 1);
} else {
@ -5696,11 +5696,11 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial)
// (Actually, this does convert column positions into character
// positions)
curwin->w_cursor.lnum = oap->end.lnum;
coladvance(oap->end_vcol);
coladvance(curwin, oap->end_vcol);
oap->end = curwin->w_cursor;
curwin->w_cursor = oap->start;
coladvance(oap->start_vcol);
coladvance(curwin, oap->start_vcol);
oap->start = curwin->w_cursor;
}
@ -5825,7 +5825,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
if (redo_VIsual.rv_vcol == MAXCOL || VIsual_mode == 'v') {
if (VIsual_mode == 'v') {
if (redo_VIsual.rv_line_count <= 1) {
validate_virtcol();
validate_virtcol(curwin);
curwin->w_curswant = curwin->w_virtcol + redo_VIsual.rv_vcol - 1;
} else {
curwin->w_curswant = redo_VIsual.rv_vcol;
@ -5833,7 +5833,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
} else {
curwin->w_curswant = MAXCOL;
}
coladvance(curwin->w_curswant);
coladvance(curwin, curwin->w_curswant);
}
cap->count0 = redo_VIsual.rv_count;
cap->count1 = (cap->count0 == 0 ? 1 : cap->count0);
@ -5880,13 +5880,13 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
if (lt(oap->start, curwin->w_cursor)) {
// Include folded lines completely.
if (!VIsual_active) {
if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) {
if (hasFolding(curwin, oap->start.lnum, &oap->start.lnum, NULL)) {
oap->start.col = 0;
}
if ((curwin->w_cursor.col > 0
|| oap->inclusive
|| oap->motion_type == kMTLineWise)
&& hasFolding(curwin->w_cursor.lnum, NULL,
&& hasFolding(curwin, curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum)) {
curwin->w_cursor.col = (colnr_T)strlen(get_cursor_line_ptr());
}
@ -5901,11 +5901,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
} else {
// Include folded lines completely.
if (!VIsual_active && oap->motion_type == kMTLineWise) {
if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
if (hasFolding(curwin, curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
NULL)) {
curwin->w_cursor.col = 0;
}
if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) {
if (hasFolding(curwin, oap->start.lnum, NULL, &oap->start.lnum)) {
oap->start.col = (colnr_T)strlen(ml_get(oap->start.lnum));
}
}
@ -5918,7 +5918,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
oap->line_count = oap->end.lnum - oap->start.lnum + 1;
// Set "virtual_op" before resetting VIsual_active.
virtual_op = virtual_active();
virtual_op = virtual_active(curwin);
if (VIsual_active || redo_VIsual_busy) {
get_op_vcol(oap, redo_VIsual.rv_vcol, true);
@ -6149,7 +6149,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
oap->excl_tr_ws = cap->cmdchar == 'z';
op_yank(oap, !gui_yank);
}
check_cursor_col();
check_cursor_col(curwin);
break;
case OP_CHANGE:
@ -6223,7 +6223,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
} else {
op_tilde(oap);
}
check_cursor_col();
check_cursor_col(curwin);
break;
case OP_FORMAT:
@ -6341,7 +6341,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
op_addsub(oap, (linenr_T)cap->count1, redo_VIsual.rv_arg);
VIsual_active = false;
}
check_cursor_col();
check_cursor_col(curwin);
break;
default:
clearopbeep(oap);
@ -6353,7 +6353,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
&& (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|| oap->op_type == OP_DELETE)) {
reset_lbr();
coladvance(curwin->w_curswant = old_col);
coladvance(curwin, curwin->w_curswant = old_col);
}
} else {
curwin->w_cursor = old_cursor;

View File

@ -1937,7 +1937,7 @@ static const char *did_set_arabic(optset_T *args)
// set rightleft mode
if (!win->w_p_rl) {
win->w_p_rl = true;
changed_window_setting();
changed_window_setting(curwin);
}
// Enable Arabic shaping (major part of what Arabic requires)
@ -1968,7 +1968,7 @@ static const char *did_set_arabic(optset_T *args)
// reset rightleft mode
if (win->w_p_rl) {
win->w_p_rl = false;
changed_window_setting();
changed_window_setting(curwin);
}
// 'arabicshape' isn't reset, it is a global option and
@ -3029,7 +3029,7 @@ void check_redraw_for(buf_T *buf, win_T *win, uint32_t flags)
if (flags & P_HLONLY) {
redraw_later(win, UPD_NOT_VALID);
} else {
changed_window_setting_win(win);
changed_window_setting(win);
}
}
if (flags & P_RBUF) {
@ -6104,9 +6104,9 @@ char *get_flp_value(buf_T *buf)
}
/// Get the local or global value of the 'virtualedit' flags.
unsigned get_ve_flags(void)
unsigned get_ve_flags(win_T *wp)
{
return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) & ~(VE_NONE | VE_NONEU);
return (wp->w_ve_flags ? wp->w_ve_flags : ve_flags) & ~(VE_NONE | VE_NONEU);
}
/// Get the local or global value of 'showbreak'.

View File

@ -2479,9 +2479,8 @@ const char *did_set_virtualedit(optset_T *args)
} else if (strcmp(ve, args->os_oldval.string.data) != 0) {
// Recompute cursor position in case the new 've' setting
// changes something.
validate_virtcol_win(win);
// XXX: this only works when win == curwin
coladvance(win->w_virtcol);
validate_virtcol(win);
coladvance(win, win->w_virtcol);
}
}
return NULL;

View File

@ -540,7 +540,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
if (ci.chr.value == TAB
&& (State & MODE_NORMAL)
&& !wp->w_p_list
&& !virtual_active()
&& !virtual_active(wp)
&& !(VIsual_active && ((*p_sel == 'e') || ltoreq(*pos, VIsual)))) {
// cursor at end
*cursor = vcol + incr - 1;
@ -583,7 +583,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e
{
colnr_T col;
if (virtual_active()) {
if (virtual_active(wp)) {
// For virtual mode, only want one value
getvcol(wp, pos, &col, NULL, NULL);
@ -902,7 +902,7 @@ int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_
if (start_vcol >= 0) {
linenr_T lnum_next = lnum;
const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL);
const bool folded = hasFolding(wp, lnum, &lnum, &lnum_next);
height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false);
height_sum_nofill += height_cur_nofill;
const int64_t row_off = (start_vcol < width1 || width2 <= 0)
@ -914,7 +914,7 @@ int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_
while (lnum <= end_lnum) {
linenr_T lnum_next = lnum;
const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL);
const bool folded = hasFolding(wp, lnum, &lnum, &lnum_next);
height_sum_fill += win_get_fill(wp, lnum);
height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false);
height_sum_nofill += height_cur_nofill;

View File

@ -140,7 +140,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// to avoid that must_redraw is set when 'cursorcolumn' is on.
pum_is_visible = true;
pum_is_drawn = true;
validate_cursor_col();
validate_cursor_col(curwin);
int above_row = 0;
int below_row = cmdline_row;
@ -273,7 +273,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
context_lines = 0;
} else {
// Leave two lines of context if possible
validate_cheight();
validate_cheight(curwin);
if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) {
context_lines = 3;
} else {
@ -995,7 +995,7 @@ static bool pum_set_selected(int n, int repeat)
}
// Return cursor to where we were
validate_cursor();
validate_cursor(curwin);
redraw_later(curwin, UPD_SOME_VALID);
// When the preview window was resized we need to

View File

@ -2889,12 +2889,12 @@ static void qf_jump_goto_line(linenr_T qf_lnum, int qf_col, char qf_viscol, char
if (qf_col > 0) {
curwin->w_cursor.coladd = 0;
if (qf_viscol == true) {
coladvance(qf_col - 1);
coladvance(curwin, qf_col - 1);
} else {
curwin->w_cursor.col = qf_col - 1;
}
curwin->w_set_curswant = true;
check_cursor();
check_cursor(curwin);
} else {
beginline(BL_WHITE | BL_FIX);
}
@ -3831,7 +3831,7 @@ void ex_copen(exarg_T *eap)
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = 0;
check_cursor();
check_cursor(curwin);
update_topline(curwin); // scroll to show the line
}

View File

@ -1076,11 +1076,11 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, int count, in
// If the cursor is in a closed fold, don't find another match in the same
// fold.
if (dirc == '/') {
if (hasFolding(pos.lnum, NULL, &pos.lnum)) {
if (hasFolding(curwin, pos.lnum, NULL, &pos.lnum)) {
pos.col = MAXCOL - 2; // avoid overflow when adding 1
}
} else {
if (hasFolding(pos.lnum, &pos.lnum, NULL)) {
if (hasFolding(curwin, pos.lnum, &pos.lnum, NULL)) {
pos.col = 0;
}
}
@ -1389,7 +1389,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, int count, in
show_top_bot_msg, msgbuf,
(count != 1 || has_offset
|| (!(fdo_flags & FDO_SEARCH)
&& hasFolding(curwin->w_cursor.lnum, NULL,
&& hasFolding(curwin, curwin->w_cursor.lnum, NULL,
NULL))),
SEARCH_STAT_DEF_MAX_COUNT,
SEARCH_STAT_DEF_TIMEOUT);
@ -4034,7 +4034,7 @@ search_line:
setpcmark();
}
curwin->w_cursor.lnum = lnum;
check_cursor();
check_cursor(curwin);
} else {
if (!GETFILE_SUCCESS(getfile(0, files[depth].name, NULL, true,
files[depth].lnum, forceit))) {
@ -4053,7 +4053,7 @@ search_line:
if (l_g_do_tagpreview != 0
&& curwin != curwin_save && win_valid(curwin_save)) {
// Return cursor to where we were
validate_cursor();
validate_cursor(curwin);
redraw_later(curwin, UPD_VALID);
win_enter(curwin_save, true);
}

View File

@ -135,9 +135,9 @@ void state_handle_k_event(void)
}
/// Return true if in the current mode we need to use virtual.
bool virtual_active(void)
bool virtual_active(win_T *wp)
{
unsigned cur_ve_flags = get_ve_flags();
unsigned cur_ve_flags = get_ve_flags(wp);
// While an operator is being executed we return "virtual_op", because
// VIsual_active has already been reset, thus we can't check for "block"

View File

@ -1,6 +1,7 @@
#pragma once
#include "nvim/state_defs.h" // IWYU pragma: keep
#include "nvim/types_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "state.h.generated.h"

View File

@ -449,7 +449,7 @@ void do_tag(char *tag, int type, int count, int forceit, bool verbose)
}
curwin->w_cursor.col = saved_fmark.mark.col;
curwin->w_set_curswant = true;
check_cursor();
check_cursor(curwin);
if ((fdo_flags & FDO_TAG) && old_KeyTyped) {
foldOpenCursor();
}
@ -3002,7 +3002,7 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, bool keep_help)
// A search command may have positioned the cursor beyond the end
// of the line. May need to correct that here.
check_cursor();
check_cursor(curwin);
} else {
const int save_secure = secure;
@ -3047,7 +3047,7 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, bool keep_help)
if (l_g_do_tagpreview != 0
&& curwin != curwin_save && win_valid(curwin_save)) {
// Return cursor to where we were
validate_cursor();
validate_cursor(curwin);
redraw_later(curwin, UPD_VALID);
win_enter(curwin_save, true);
}

View File

@ -612,7 +612,7 @@ static void terminal_check_cursor(void)
row_to_linenr(term, term->cursor.row));
// Nudge cursor when returning to normal-mode.
int off = is_focused(term) ? 0 : (curwin->w_p_rl ? 1 : -1);
coladvance(MAX(0, term->cursor.col + off));
coladvance(curwin, MAX(0, term->cursor.col + off));
}
// Function executed before each iteration of terminal mode.
@ -626,7 +626,7 @@ static int terminal_check(VimState *state)
}
terminal_check_cursor();
validate_cursor();
validate_cursor(curwin);
if (must_redraw) {
update_screen();

View File

@ -157,7 +157,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
}
// find column of textwidth border
coladvance((colnr_T)textwidth);
coladvance(curwin, (colnr_T)textwidth);
wantcol = curwin->w_cursor.col;
// If startcol is large (a long line), formatting takes too much
@ -690,9 +690,9 @@ void auto_format(bool trailblank, bool prev_line)
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
// "cannot happen"
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
} else {
check_cursor_col();
check_cursor_col(curwin);
}
// Insert mode: If the cursor is now after the end of the line while it
@ -715,7 +715,7 @@ void auto_format(bool trailblank, bool prev_line)
}
}
check_cursor();
check_cursor(curwin);
}
/// When an extra space was added to continue a paragraph for auto-formatting,
@ -839,7 +839,7 @@ void op_format(oparg_T *oap, bool keep_cursor)
saved_cursor.lnum = 0;
// formatting may have made the cursor position invalid
check_cursor();
check_cursor(curwin);
}
if (oap->is_VIsual) {
@ -1063,7 +1063,7 @@ void format_lines(linenr_T line_count, bool avoid_fex)
// put cursor on last non-space
State = MODE_NORMAL; // don't go past end-of-line
coladvance(MAXCOL);
coladvance(curwin, MAXCOL);
while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) {
dec_cursor();
}

View File

@ -187,7 +187,7 @@ bool findpar(bool *pincl, int dir, int count, int what, bool both)
// skip folded lines
fold_skipped = false;
if (first && hasFolding(curr, &fold_first, &fold_last)) {
if (first && hasFolding(curwin, curr, &fold_first, &fold_last)) {
curr = ((dir > 0) ? fold_last : fold_first) + dir;
fold_skipped = true;
}
@ -318,8 +318,8 @@ int fwd_word(int count, bool bigword, bool eol)
while (--count >= 0) {
// When inside a range of folded lines, move to the last char of the
// last line.
if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) {
coladvance(MAXCOL);
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) {
coladvance(curwin, MAXCOL);
}
int sclass = cls(); // starting class
@ -374,7 +374,7 @@ int bck_word(int count, bool bigword, bool stop)
while (--count >= 0) {
// When inside a range of folded lines, move to the first char of the
// first line.
if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL)) {
if (hasFolding(curwin, curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL)) {
curwin->w_cursor.col = 0;
}
sclass = cls();
@ -431,8 +431,8 @@ int end_word(int count, bool bigword, bool stop, bool empty)
while (--count >= 0) {
// When inside a range of folded lines, move to the last char of the
// last line.
if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) {
coladvance(MAXCOL);
if (hasFolding(curwin, curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) {
coladvance(curwin, MAXCOL);
}
sclass = cls();
if (inc_cursor() == -1) {

View File

@ -477,7 +477,7 @@ int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, bool r
uhp->uh_entry = NULL;
uhp->uh_getbot_entry = NULL;
uhp->uh_cursor = curwin->w_cursor; // save cursor pos. for undo
if (virtual_active() && curwin->w_cursor.coladd > 0) {
if (virtual_active(curwin) && curwin->w_cursor.coladd > 0) {
uhp->uh_cursor_vcol = getviscol();
} else {
uhp->uh_cursor_vcol = -1;
@ -2488,8 +2488,8 @@ static void u_undoredo(bool undo, bool do_buf_event)
if (curwin->w_cursor.lnum <= curbuf->b_ml.ml_line_count) {
if (curhead->uh_cursor.lnum == curwin->w_cursor.lnum) {
curwin->w_cursor.col = curhead->uh_cursor.col;
if (virtual_active() && curhead->uh_cursor_vcol >= 0) {
coladvance(curhead->uh_cursor_vcol);
if (virtual_active(curwin) && curhead->uh_cursor_vcol >= 0) {
coladvance(curwin, curhead->uh_cursor_vcol);
} else {
curwin->w_cursor.coladd = 0;
}
@ -2506,7 +2506,7 @@ static void u_undoredo(bool undo, bool do_buf_event)
}
// Make sure the cursor is on an existing line and column.
check_cursor();
check_cursor(curwin);
// Remember where we are for "g-" and ":earlier 10s".
curbuf->b_u_seq_cur = curhead->uh_seq;
@ -3073,7 +3073,7 @@ void u_undoline(void)
}
curwin->w_cursor.col = t;
curwin->w_cursor.lnum = curbuf->b_u_line_lnum;
check_cursor_col();
check_cursor_col(curwin);
}
/// Allocate memory and copy curbuf line into it.

View File

@ -766,7 +766,7 @@ void win_set_buf(win_T *win, buf_T *buf, bool noautocmd, Error *err)
// If window is not current, state logic will not validate its cursor. So do it now.
// Still needed if do_buffer returns FAIL (e.g: autocmds abort script after buffer was set).
validate_cursor();
validate_cursor(curwin);
cleanup:
restore_win_noblock(&switchwin, true);
@ -2872,7 +2872,7 @@ int win_close(win_T *win, bool free_buf, bool force)
// The cursor position may be invalid if the buffer changed after last
// using the window.
check_cursor();
check_cursor(curwin);
}
if (!was_floating) {
@ -4921,8 +4921,8 @@ static void win_enter_ext(win_T *const wp, const int flags)
curwin = wp;
curbuf = wp->w_buffer;
check_cursor();
if (!virtual_active()) {
check_cursor(curwin);
if (!virtual_active(curwin)) {
curwin->w_cursor.coladd = 0;
}
if (*p_spk == 'c') {
@ -6638,7 +6638,7 @@ void scroll_to_fraction(win_T *wp, int prev_height)
}
} else if (sline > 0) {
while (sline > 0 && lnum > 1) {
hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
hasFolding(wp, lnum, &lnum, NULL);
if (lnum == 1) {
// first line in buffer is folded
line_size = 1;
@ -6658,7 +6658,7 @@ void scroll_to_fraction(win_T *wp, int prev_height)
if (sline < 0) {
// Line we want at top would go off top of screen. Use next
// line instead.
hasFoldingWin(wp, lnum, NULL, &lnum, true, NULL);
hasFolding(wp, lnum, NULL, &lnum);
lnum++;
wp->w_wrow -= line_size + sline;
} else if (sline > 0) {
@ -6699,7 +6699,7 @@ void win_set_inner_size(win_T *wp, bool valid_cursor)
if (wp == curwin && *p_spk == 'c') {
// w_wrow needs to be valid. When setting 'laststatus' this may
// call win_new_height() recursively.
validate_cursor();
validate_cursor(curwin);
}
if (wp->w_height_inner != prev_height) {
return; // Recursive call already changed the size, bail out.

View File

@ -136,7 +136,7 @@ function ChildProcessStream.spawn(argv, env, io_extra)
end
--- @diagnostic disable-next-line:missing-fields
self._proc, self._pid = uv.spawn(prog, {
stdio = { self._child_stdin, self._child_stdout, 2, io_extra },
stdio = { self._child_stdin, self._child_stdout, 1, io_extra },
args = args,
--- @diagnostic disable-next-line:assign-type-mismatch
env = env,

View File

@ -121,6 +121,66 @@ describe('api/buf', function()
eq({ 5, 2 }, api.nvim_win_get_cursor(win2))
end)
it('cursor position is maintained consistently with viewport', function()
local screen = Screen.new(20, 12)
screen:set_default_attr_ids {
[1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = { reverse = true, bold = true },
[3] = { reverse = true },
}
screen:attach()
local lines = { 'line1', 'line2', 'line3', 'line4', 'line5', 'line6' }
local buf = api.nvim_get_current_buf()
api.nvim_buf_set_lines(buf, 0, -1, true, lines)
command('6')
command('new')
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
line5 |
line6 |
{1:~ }|*2
{3:[No Name] [+] }|
|
]],
}
api.nvim_buf_set_lines(buf, 0, -1, true, lines)
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
line3 |
line4 |
line5 |
line6 |
{3:[No Name] [+] }|
|
]],
}
command('wincmd w')
screen:expect {
grid = [[
|
{1:~ }|*4
{3:[No Name] }|
line3 |
line4 |
line5 |
^line6 |
{2:[No Name] [+] }|
|
]],
}
end)
it('line_count has defined behaviour for unloaded buffers', function()
-- we'll need to know our bufnr for when it gets unloaded
local bufnr = api.nvim_buf_get_number(0)
@ -323,20 +383,20 @@ describe('api/buf', function()
]],
}
-- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
mmm |
wwweeee |
xxx |
yyy |
zzz |
{3:[No Name] [+] }|
|
]],
unchanged = true,
}
end)
@ -402,7 +462,6 @@ describe('api/buf', function()
]],
}
-- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
@ -412,10 +471,10 @@ describe('api/buf', function()
mmm |
wwweeee |
{2:[No Name] [+] }|
mmm |
wwweeee |
xxx |
yyy |
zzz |
{3:[No Name] [+] }|
|
]],

View File

@ -13,15 +13,19 @@ describe('ffi.cdef', function()
eq(
12,
exec_lua [[
exec_lua [=[
local ffi = require('ffi')
ffi.cdef('int curwin_col_off(void);')
ffi.cdef [[
typedef struct window_S win_T;
int win_col_off(win_T *wp);
extern win_T *curwin;
]]
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
return ffi.C.curwin_col_off()
]]
return ffi.C.win_col_off(ffi.C.curwin)
]=]
)
eq(
@ -30,7 +34,6 @@ describe('ffi.cdef', function()
local ffi = require('ffi')
ffi.cdef[[
typedef struct window_S win_T;
typedef struct {} stl_hlrec_t;
typedef struct {} StlClickRecord;
typedef struct {} statuscol_T;