move changed_common

This commit is contained in:
Daniel Hahler
2019-06-09 15:51:29 +02:00
parent 0e5314f56e
commit 53210c16d1
2 changed files with 144 additions and 346 deletions

View File

@@ -119,201 +119,167 @@ void changed_internal(void)
* See changed_lines() for the arguments. * See changed_lines() for the arguments.
* Careful: may trigger autocommands that reload the buffer. * Careful: may trigger autocommands that reload the buffer.
*/ */
static void static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
changed_common(
linenr_T lnum,
colnr_T col,
linenr_T lnume,
long xtra)
{ {
win_T *wp;
tabpage_T *tp;
int i; int i;
#ifdef FEAT_JUMPLIST
int cols; int cols;
pos_T *p; pos_T *p;
int add; int add;
#endif
// mark the buffer as modified /* mark the buffer as modified */
changed(); changed();
#ifdef FEAT_DIFF if (curwin->w_p_diff && diff_internal()) {
if (curwin->w_p_diff && diff_internal()) curtab->tp_diff_update = true;
curtab->tp_diff_update = TRUE; }
#endif
// set the '. mark /* set the '. mark */
if (!cmdmod.keepjumps) if (!cmdmod.keepjumps) {
{ RESET_FMARK(&curbuf->b_last_change, ((pos_T) {lnum, col, 0}), 0);
curbuf->b_last_change.lnum = lnum;
curbuf->b_last_change.col = col;
#ifdef FEAT_JUMPLIST /* Create a new entry if a new undo-able change was started or we
// Create a new entry if a new undo-able change was started or we * don't have an entry yet. */
// don't have an entry yet. if (curbuf->b_new_change || curbuf->b_changelistlen == 0) {
if (curbuf->b_new_change || curbuf->b_changelistlen == 0)
{
if (curbuf->b_changelistlen == 0) if (curbuf->b_changelistlen == 0)
add = TRUE; add = TRUE;
else else {
{ /* Don't create a new entry when the line number is the same
// Don't create a new entry when the line number is the same * as the last one and the column is not too far away. Avoids
// as the last one and the column is not too far away. Avoids * creating many entries for typing "xxxxx". */
// creating many entries for typing "xxxxx". p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark;
p = &curbuf->b_changelist[curbuf->b_changelistlen - 1];
if (p->lnum != lnum) if (p->lnum != lnum)
add = TRUE; add = TRUE;
else else {
{
cols = comp_textwidth(FALSE); cols = comp_textwidth(FALSE);
if (cols == 0) if (cols == 0)
cols = 79; cols = 79;
add = (p->col + cols < col || col + cols < p->col); add = (p->col + cols < col || col + cols < p->col);
} }
} }
if (add) if (add) {
{ /* This is the first of a new sequence of undo-able changes
// This is the first of a new sequence of undo-able changes * and it's at some distance of the last change. Use a new
// and it's at some distance of the last change. Use a new * position in the changelist. */
// position in the changelist. curbuf->b_new_change = false;
curbuf->b_new_change = FALSE;
if (curbuf->b_changelistlen == JUMPLISTSIZE) if (curbuf->b_changelistlen == JUMPLISTSIZE) {
{ /* changelist is full: remove oldest entry */
// changelist is full: remove oldest entry
curbuf->b_changelistlen = JUMPLISTSIZE - 1; curbuf->b_changelistlen = JUMPLISTSIZE - 1;
mch_memmove(curbuf->b_changelist, curbuf->b_changelist + 1, memmove(curbuf->b_changelist, curbuf->b_changelist + 1,
sizeof(pos_T) * (JUMPLISTSIZE - 1)); sizeof(curbuf->b_changelist[0]) * (JUMPLISTSIZE - 1));
FOR_ALL_TAB_WINDOWS(tp, wp) FOR_ALL_TAB_WINDOWS(tp, wp) {
{ /* Correct position in changelist for other windows on
// Correct position in changelist for other windows on * this buffer. */
// this buffer. if (wp->w_buffer == curbuf && wp->w_changelistidx > 0) {
if (wp->w_buffer == curbuf && wp->w_changelistidx > 0)
--wp->w_changelistidx; --wp->w_changelistidx;
} }
} }
FOR_ALL_TAB_WINDOWS(tp, wp) }
{ FOR_ALL_TAB_WINDOWS(tp, wp) {
// For other windows, if the position in the changelist is /* For other windows, if the position in the changelist is
// at the end it stays at the end. * at the end it stays at the end. */
if (wp->w_buffer == curbuf if (wp->w_buffer == curbuf
&& wp->w_changelistidx == curbuf->b_changelistlen) && wp->w_changelistidx == curbuf->b_changelistlen) {
++wp->w_changelistidx; ++wp->w_changelistidx;
} }
}
++curbuf->b_changelistlen; ++curbuf->b_changelistlen;
} }
} }
curbuf->b_changelist[curbuf->b_changelistlen - 1] = curbuf->b_changelist[curbuf->b_changelistlen - 1] =
curbuf->b_last_change; curbuf->b_last_change;
// The current window is always after the last change, so that "g," /* The current window is always after the last change, so that "g,"
// takes you back to it. * takes you back to it. */
curwin->w_changelistidx = curbuf->b_changelistlen; curwin->w_changelistidx = curbuf->b_changelistlen;
#endif
} }
FOR_ALL_TAB_WINDOWS(tp, wp) FOR_ALL_TAB_WINDOWS(tp, wp) {
{ if (wp->w_buffer == curbuf) {
if (wp->w_buffer == curbuf) /* Mark this window to be redrawn later. */
{
// Mark this window to be redrawn later.
if (wp->w_redr_type < VALID) if (wp->w_redr_type < VALID)
wp->w_redr_type = VALID; wp->w_redr_type = VALID;
// Check if a change in the buffer has invalidated the cached /* Check if a change in the buffer has invalidated the cached
// values for the cursor. * values for the cursor. */
#ifdef FEAT_FOLDING /*
// Update the folds for this window. Can't postpone this, because * Update the folds for this window. Can't postpone this, because
// a following operator might work on the whole fold: ">>dd". * a following operator might work on the whole fold: ">>dd".
*/
foldUpdate(wp, lnum, lnume + xtra - 1); foldUpdate(wp, lnum, lnume + xtra - 1);
// The change may cause lines above or below the change to become /* The change may cause lines above or below the change to become
// included in a fold. Set lnum/lnume to the first/last line that * included in a fold. Set lnum/lnume to the first/last line that
// might be displayed differently. * might be displayed differently.
// Set w_cline_folded here as an efficient way to update it when * Set w_cline_folded here as an efficient way to update it when
// inserting lines just above a closed fold. * inserting lines just above a closed fold. */
i = hasFoldingWin(wp, lnum, &lnum, NULL, FALSE, NULL); bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL);
if (wp->w_cursor.lnum == lnum) if (wp->w_cursor.lnum == lnum)
wp->w_cline_folded = i; wp->w_cline_folded = folded;
i = hasFoldingWin(wp, lnume, NULL, &lnume, FALSE, NULL); folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL);
if (wp->w_cursor.lnum == lnume) if (wp->w_cursor.lnum == lnume)
wp->w_cline_folded = i; wp->w_cline_folded = folded;
// If the changed line is in a range of previously folded lines, /* If the changed line is in a range of previously folded lines,
// compare with the first line in that range. * compare with the first line in that range. */
if (wp->w_cursor.lnum <= lnum) if (wp->w_cursor.lnum <= lnum) {
{
i = find_wl_entry(wp, lnum); i = find_wl_entry(wp, lnum);
if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum) if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum)
changed_line_abv_curs_win(wp); changed_line_abv_curs_win(wp);
} }
#endif
if (wp->w_cursor.lnum > lnum) if (wp->w_cursor.lnum > lnum)
changed_line_abv_curs_win(wp); changed_line_abv_curs_win(wp);
else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col) else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col)
changed_cline_bef_curs_win(wp); changed_cline_bef_curs_win(wp);
if (wp->w_botline >= lnum) if (wp->w_botline >= lnum) {
{ /* Assume that botline doesn't change (inserted lines make
// Assume that botline doesn't change (inserted lines make * other lines scroll down below botline). */
// other lines scroll down below botline).
approximate_botline_win(wp); approximate_botline_win(wp);
} }
// Check if any w_lines[] entries have become invalid. /* Check if any w_lines[] entries have become invalid.
// For entries below the change: Correct the lnums for * For entries below the change: Correct the lnums for
// inserted/deleted lines. Makes it possible to stop displaying * inserted/deleted lines. Makes it possible to stop displaying
// after the change. * after the change. */
for (i = 0; i < wp->w_lines_valid; ++i) for (i = 0; i < wp->w_lines_valid; ++i)
if (wp->w_lines[i].wl_valid) if (wp->w_lines[i].wl_valid) {
{ if (wp->w_lines[i].wl_lnum >= lnum) {
if (wp->w_lines[i].wl_lnum >= lnum) if (wp->w_lines[i].wl_lnum < lnume) {
{ /* line included in change */
if (wp->w_lines[i].wl_lnum < lnume)
{
// line included in change
wp->w_lines[i].wl_valid = FALSE; wp->w_lines[i].wl_valid = FALSE;
} } else if (xtra != 0) {
else if (xtra != 0) /* line below change */
{
// line below change
wp->w_lines[i].wl_lnum += xtra; wp->w_lines[i].wl_lnum += xtra;
#ifdef FEAT_FOLDING
wp->w_lines[i].wl_lastlnum += xtra; wp->w_lines[i].wl_lastlnum += xtra;
#endif
} }
} } else if (wp->w_lines[i].wl_lastlnum >= lnum) {
#ifdef FEAT_FOLDING /* change somewhere inside this range of folded lines,
else if (wp->w_lines[i].wl_lastlnum >= lnum) * may need to be redrawn */
{
// change somewhere inside this range of folded lines,
// may need to be redrawn
wp->w_lines[i].wl_valid = FALSE; wp->w_lines[i].wl_valid = FALSE;
} }
#endif
} }
#ifdef FEAT_FOLDING /* Take care of side effects for setting w_topline when folds have
// Take care of side effects for setting w_topline when folds have * changed. Esp. when the buffer was changed in another window. */
// changed. Esp. when the buffer was changed in another window.
if (hasAnyFolding(wp)) if (hasAnyFolding(wp))
set_topline(wp, wp->w_topline); set_topline(wp, wp->w_topline);
#endif
// relative numbering may require updating more // relative numbering may require updating more
if (wp->w_p_rnu) if (wp->w_p_rnu) {
redraw_win_later(wp, SOME_VALID); redraw_win_later(wp, SOME_VALID);
} }
} }
}
// Call update_screen() later, which checks out what needs to be redrawn, /* Call update_screen() later, which checks out what needs to be redrawn,
// since it notices b_mod_set and then uses b_mod_*. * since it notices b_mod_set and then uses b_mod_*. */
if (must_redraw < VALID) if (must_redraw < VALID)
must_redraw = VALID; must_redraw = VALID;
// when the cursor line is changed always trigger CursorMoved /* when the cursor line is changed always trigger CursorMoved */
if (lnum <= curwin->w_cursor.lnum if (lnum <= curwin->w_cursor.lnum
&& lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum) && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum)
last_cursormoved.lnum = 0; curwin->w_last_cursormoved.lnum = 0;
} }
static void static void

View File

@@ -1959,174 +1959,6 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
} }
} }
/*
* Common code for when a change is was made.
* See changed_lines() for the arguments.
* Careful: may trigger autocommands that reload the buffer.
*/
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
{
int i;
int cols;
pos_T *p;
int add;
/* mark the buffer as modified */
changed();
if (curwin->w_p_diff && diff_internal()) {
curtab->tp_diff_update = true;
}
/* set the '. mark */
if (!cmdmod.keepjumps) {
RESET_FMARK(&curbuf->b_last_change, ((pos_T) {lnum, col, 0}), 0);
/* Create a new entry if a new undo-able change was started or we
* don't have an entry yet. */
if (curbuf->b_new_change || curbuf->b_changelistlen == 0) {
if (curbuf->b_changelistlen == 0)
add = TRUE;
else {
/* Don't create a new entry when the line number is the same
* as the last one and the column is not too far away. Avoids
* creating many entries for typing "xxxxx". */
p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark;
if (p->lnum != lnum)
add = TRUE;
else {
cols = comp_textwidth(FALSE);
if (cols == 0)
cols = 79;
add = (p->col + cols < col || col + cols < p->col);
}
}
if (add) {
/* This is the first of a new sequence of undo-able changes
* and it's at some distance of the last change. Use a new
* position in the changelist. */
curbuf->b_new_change = false;
if (curbuf->b_changelistlen == JUMPLISTSIZE) {
/* changelist is full: remove oldest entry */
curbuf->b_changelistlen = JUMPLISTSIZE - 1;
memmove(curbuf->b_changelist, curbuf->b_changelist + 1,
sizeof(curbuf->b_changelist[0]) * (JUMPLISTSIZE - 1));
FOR_ALL_TAB_WINDOWS(tp, wp) {
/* Correct position in changelist for other windows on
* this buffer. */
if (wp->w_buffer == curbuf && wp->w_changelistidx > 0) {
--wp->w_changelistidx;
}
}
}
FOR_ALL_TAB_WINDOWS(tp, wp) {
/* For other windows, if the position in the changelist is
* at the end it stays at the end. */
if (wp->w_buffer == curbuf
&& wp->w_changelistidx == curbuf->b_changelistlen) {
++wp->w_changelistidx;
}
}
++curbuf->b_changelistlen;
}
}
curbuf->b_changelist[curbuf->b_changelistlen - 1] =
curbuf->b_last_change;
/* The current window is always after the last change, so that "g,"
* takes you back to it. */
curwin->w_changelistidx = curbuf->b_changelistlen;
}
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == curbuf) {
/* Mark this window to be redrawn later. */
if (wp->w_redr_type < VALID)
wp->w_redr_type = VALID;
/* Check if a change in the buffer has invalidated the cached
* values for the cursor. */
/*
* Update the folds for this window. Can't postpone this, because
* a following operator might work on the whole fold: ">>dd".
*/
foldUpdate(wp, lnum, lnume + xtra - 1);
/* The change may cause lines above or below the change to become
* included in a fold. Set lnum/lnume to the first/last line that
* might be displayed differently.
* Set w_cline_folded here as an efficient way to update it when
* inserting lines just above a closed fold. */
bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL);
if (wp->w_cursor.lnum == lnum)
wp->w_cline_folded = folded;
folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL);
if (wp->w_cursor.lnum == lnume)
wp->w_cline_folded = folded;
/* If the changed line is in a range of previously folded lines,
* compare with the first line in that range. */
if (wp->w_cursor.lnum <= lnum) {
i = find_wl_entry(wp, lnum);
if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum)
changed_line_abv_curs_win(wp);
}
if (wp->w_cursor.lnum > lnum)
changed_line_abv_curs_win(wp);
else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col)
changed_cline_bef_curs_win(wp);
if (wp->w_botline >= lnum) {
/* Assume that botline doesn't change (inserted lines make
* other lines scroll down below botline). */
approximate_botline_win(wp);
}
/* Check if any w_lines[] entries have become invalid.
* For entries below the change: Correct the lnums for
* inserted/deleted lines. Makes it possible to stop displaying
* after the change. */
for (i = 0; i < wp->w_lines_valid; ++i)
if (wp->w_lines[i].wl_valid) {
if (wp->w_lines[i].wl_lnum >= lnum) {
if (wp->w_lines[i].wl_lnum < lnume) {
/* line included in change */
wp->w_lines[i].wl_valid = FALSE;
} else if (xtra != 0) {
/* line below change */
wp->w_lines[i].wl_lnum += xtra;
wp->w_lines[i].wl_lastlnum += xtra;
}
} else if (wp->w_lines[i].wl_lastlnum >= lnum) {
/* change somewhere inside this range of folded lines,
* may need to be redrawn */
wp->w_lines[i].wl_valid = FALSE;
}
}
/* Take care of side effects for setting w_topline when folds have
* changed. Esp. when the buffer was changed in another window. */
if (hasAnyFolding(wp))
set_topline(wp, wp->w_topline);
// relative numbering may require updating more
if (wp->w_p_rnu) {
redraw_win_later(wp, SOME_VALID);
}
}
}
/* Call update_screen() later, which checks out what needs to be redrawn,
* since it notices b_mod_set and then uses b_mod_*. */
if (must_redraw < VALID)
must_redraw = VALID;
/* when the cursor line is changed always trigger CursorMoved */
if (lnum <= curwin->w_cursor.lnum
&& lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum)
curwin->w_last_cursormoved.lnum = 0;
}
/* /*
* unchanged() is called when the changed flag must be reset for buffer 'buf' * unchanged() is called when the changed flag must be reset for buffer 'buf'
*/ */