mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
bufhl: fix move
This commit is contained in:
parent
7873660e1e
commit
8b375cf471
@ -399,7 +399,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
// Only adjust marks if we managed to switch to a window that holds
|
// Only adjust marks if we managed to switch to a window that holds
|
||||||
// the buffer, otherwise line numbers will be invalid.
|
// the buffer, otherwise line numbers will be invalid.
|
||||||
if (save_curbuf.br_buf == NULL) {
|
if (save_curbuf.br_buf == NULL) {
|
||||||
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra);
|
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
|
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
|
||||||
|
@ -5304,6 +5304,9 @@ void bufhl_clear_all(buf_T *buf)
|
|||||||
{
|
{
|
||||||
bufhl_clear_line_range(buf, -1, 1, MAXLNUM);
|
bufhl_clear_line_range(buf, -1, 1, MAXLNUM);
|
||||||
kb_destroy(bufhl, (&buf->b_bufhl_info));
|
kb_destroy(bufhl, (&buf->b_bufhl_info));
|
||||||
|
kb_init(&buf->b_bufhl_info);
|
||||||
|
kv_destroy(buf->b_bufhl_move_space);
|
||||||
|
kv_init(buf->b_bufhl_move_space);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjust a placed highlight for inserted/deleted lines.
|
/// Adjust a placed highlight for inserted/deleted lines.
|
||||||
@ -5311,19 +5314,32 @@ void bufhl_mark_adjust(buf_T* buf,
|
|||||||
linenr_T line1,
|
linenr_T line1,
|
||||||
linenr_T line2,
|
linenr_T line2,
|
||||||
long amount,
|
long amount,
|
||||||
long amount_after)
|
long amount_after,
|
||||||
|
bool end_temp)
|
||||||
{
|
{
|
||||||
// XXX: does not support move
|
|
||||||
// we need to detect this case and
|
|
||||||
|
|
||||||
kbitr_t(bufhl) itr;
|
kbitr_t(bufhl) itr;
|
||||||
BufhlLine *l, t = BUFHLLINE_INIT(line1);
|
BufhlLine *l, t = BUFHLLINE_INIT(line1);
|
||||||
|
if (end_temp && amount < 0) {
|
||||||
|
// Move all items from b_bufhl_move_space to the btree.
|
||||||
|
for (size_t i = 0; i < kv_size(buf->b_bufhl_move_space); i++) {
|
||||||
|
l = kv_A(buf->b_bufhl_move_space, i);
|
||||||
|
l->line += amount;
|
||||||
|
kb_put(bufhl, &buf->b_bufhl_info, l);
|
||||||
|
}
|
||||||
|
kv_size(buf->b_bufhl_move_space) = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) {
|
if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) {
|
||||||
kb_itr_next(bufhl, &buf->b_bufhl_info, &itr);
|
kb_itr_next(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
}
|
}
|
||||||
for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) {
|
for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) {
|
||||||
l = kb_itr_key(&itr);
|
l = kb_itr_key(&itr);
|
||||||
if (l->line >= line1 && l->line <= line2) {
|
if (l->line >= line1 && l->line <= line2) {
|
||||||
|
if (end_temp && amount > 0) {
|
||||||
|
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
|
kv_push(buf->b_bufhl_move_space, l);
|
||||||
|
}
|
||||||
if (amount == MAXLNUM) {
|
if (amount == MAXLNUM) {
|
||||||
if (bufhl_clear_line(l, -1, l->line) == kBLSDeleted) {
|
if (bufhl_clear_line(l, -1, l->line) == kBLSDeleted) {
|
||||||
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
@ -5371,7 +5387,8 @@ bool bufhl_start_line(buf_T *buf, linenr_T lnum, BufhlLineInfo *info)
|
|||||||
/// @param info The info returned by bufhl_start_line
|
/// @param info The info returned by bufhl_start_line
|
||||||
/// @param col The column to get the attr for
|
/// @param col The column to get the attr for
|
||||||
/// @return The highilight attr to display at the column
|
/// @return The highilight attr to display at the column
|
||||||
int bufhl_get_attr(BufhlLineInfo *info, colnr_T col) {
|
int bufhl_get_attr(BufhlLineInfo *info, colnr_T col)
|
||||||
|
{
|
||||||
if (col <= info->valid_to) {
|
if (col <= info->valid_to) {
|
||||||
return info->current;
|
return info->current;
|
||||||
}
|
}
|
||||||
|
@ -761,6 +761,8 @@ struct file_buffer {
|
|||||||
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
||||||
|
|
||||||
BufhlInfo b_bufhl_info; // buffer stored highlights
|
BufhlInfo b_bufhl_info; // buffer stored highlights
|
||||||
|
|
||||||
|
kvec_t(BufhlLine *) b_bufhl_move_space; // temporary space for highlights
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2311,7 +2311,7 @@ void ex_diffgetput(exarg_T *eap)
|
|||||||
|
|
||||||
// Adjust marks. This will change the following entries!
|
// Adjust marks. This will change the following entries!
|
||||||
if (added != 0) {
|
if (added != 0) {
|
||||||
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added);
|
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added, false);
|
||||||
if (curwin->w_cursor.lnum >= lnum) {
|
if (curwin->w_cursor.lnum >= lnum) {
|
||||||
// Adjust the cursor position if it's in/after the changed
|
// Adjust the cursor position if it's in/after the changed
|
||||||
// lines.
|
// lines.
|
||||||
|
@ -597,9 +597,10 @@ void ex_sort(exarg_T *eap)
|
|||||||
// Adjust marks for deleted (or added) lines and prepare for displaying.
|
// Adjust marks for deleted (or added) lines and prepare for displaying.
|
||||||
deleted = (long)(count - (lnum - eap->line2));
|
deleted = (long)(count - (lnum - eap->line2));
|
||||||
if (deleted > 0) {
|
if (deleted > 0) {
|
||||||
mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted);
|
mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted,
|
||||||
|
false);
|
||||||
} else if (deleted < 0) {
|
} else if (deleted < 0) {
|
||||||
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L);
|
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, false);
|
||||||
}
|
}
|
||||||
changed_lines(eap->line1, 0, eap->line2 + 1, -deleted);
|
changed_lines(eap->line1, 0, eap->line2 + 1, -deleted);
|
||||||
|
|
||||||
@ -794,9 +795,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
* their final destination at the new text position -- webb
|
* their final destination at the new text position -- webb
|
||||||
*/
|
*/
|
||||||
last_line = curbuf->b_ml.ml_line_count;
|
last_line = curbuf->b_ml.ml_line_count;
|
||||||
mark_adjust_nofold(line1, line2, last_line - line2, 0L);
|
mark_adjust_nofold(line1, line2, last_line - line2, 0L, true);
|
||||||
if (dest >= line2) {
|
if (dest >= line2) {
|
||||||
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L);
|
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L, false);
|
||||||
FOR_ALL_TAB_WINDOWS(tab, win) {
|
FOR_ALL_TAB_WINDOWS(tab, win) {
|
||||||
if (win->w_buffer == curbuf) {
|
if (win->w_buffer == curbuf) {
|
||||||
foldMoveRange(&win->w_folds, line1, line2, dest);
|
foldMoveRange(&win->w_folds, line1, line2, dest);
|
||||||
@ -805,7 +806,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
curbuf->b_op_start.lnum = dest - num_lines + 1;
|
curbuf->b_op_start.lnum = dest - num_lines + 1;
|
||||||
curbuf->b_op_end.lnum = dest;
|
curbuf->b_op_end.lnum = dest;
|
||||||
} else {
|
} else {
|
||||||
mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L);
|
mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L, false);
|
||||||
FOR_ALL_TAB_WINDOWS(tab, win) {
|
FOR_ALL_TAB_WINDOWS(tab, win) {
|
||||||
if (win->w_buffer == curbuf) {
|
if (win->w_buffer == curbuf) {
|
||||||
foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
|
foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
|
||||||
@ -816,7 +817,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
}
|
}
|
||||||
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
|
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
|
||||||
mark_adjust_nofold(last_line - num_lines + 1, last_line,
|
mark_adjust_nofold(last_line - num_lines + 1, last_line,
|
||||||
-(last_line - dest - extra), 0L);
|
-(last_line - dest - extra), 0L, true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we delete the original text -- webb
|
* Now we delete the original text -- webb
|
||||||
@ -1212,15 +1213,14 @@ static void do_filter(
|
|||||||
|
|
||||||
if (do_in) {
|
if (do_in) {
|
||||||
if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) {
|
if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) {
|
||||||
if (read_linecount >= linecount)
|
if (read_linecount >= linecount) {
|
||||||
/* move all marks from old lines to new lines */
|
// move all marks from old lines to new lines
|
||||||
mark_adjust(line1, line2, linecount, 0L);
|
mark_adjust(line1, line2, linecount, 0L, false);
|
||||||
else {
|
} else {
|
||||||
/* move marks from old lines to new lines, delete marks
|
// move marks from old lines to new lines, delete marks
|
||||||
* that are in deleted lines */
|
// that are in deleted lines
|
||||||
mark_adjust(line1, line1 + read_linecount - 1,
|
mark_adjust(line1, line1 + read_linecount - 1, linecount, 0L, false);
|
||||||
linecount, 0L);
|
mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L, false);
|
||||||
mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3758,7 +3758,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout)
|
|||||||
*p1 = NUL; // truncate up to the CR
|
*p1 = NUL; // truncate up to the CR
|
||||||
ml_append(lnum - 1, new_start,
|
ml_append(lnum - 1, new_start,
|
||||||
(colnr_T)(p1 - new_start + 1), false);
|
(colnr_T)(p1 - new_start + 1), false);
|
||||||
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
|
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, false);
|
||||||
if (subflags.do_ask) {
|
if (subflags.do_ask) {
|
||||||
appended_lines(lnum - 1, 1L);
|
appended_lines(lnum - 1, 1L);
|
||||||
} else {
|
} else {
|
||||||
@ -3847,7 +3847,7 @@ skip:
|
|||||||
for (i = 0; i < nmatch_tl; ++i)
|
for (i = 0; i < nmatch_tl; ++i)
|
||||||
ml_delete(lnum, (int)FALSE);
|
ml_delete(lnum, (int)FALSE);
|
||||||
mark_adjust(lnum, lnum + nmatch_tl - 1,
|
mark_adjust(lnum, lnum + nmatch_tl - 1,
|
||||||
(long)MAXLNUM, -nmatch_tl);
|
(long)MAXLNUM, -nmatch_tl, false);
|
||||||
if (subflags.do_ask) {
|
if (subflags.do_ask) {
|
||||||
deleted_lines(lnum, nmatch_tl);
|
deleted_lines(lnum, nmatch_tl);
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,10 @@
|
|||||||
} \
|
} \
|
||||||
static inline int kb_itr_getp_##name(kbtree_##name##_t *b, key_t * __restrict k, kbitr_##name##_t *itr) \
|
static inline int kb_itr_getp_##name(kbtree_##name##_t *b, key_t * __restrict k, kbitr_##name##_t *itr) \
|
||||||
{ \
|
{ \
|
||||||
if (b->n_keys == 0) return 0; \
|
if (b->n_keys == 0) { \
|
||||||
|
itr->p = NULL; \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
int i, r = 0; \
|
int i, r = 0; \
|
||||||
itr->p = itr->stack; \
|
itr->p = itr->stack; \
|
||||||
itr->p->x = b->root; \
|
itr->p->x = b->root; \
|
||||||
@ -420,6 +423,7 @@
|
|||||||
|
|
||||||
#define kbtree_t(name) kbtree_##name##_t
|
#define kbtree_t(name) kbtree_##name##_t
|
||||||
#define kbitr_t(name) kbitr_##name##_t
|
#define kbitr_t(name) kbitr_##name##_t
|
||||||
|
#define kb_init(b) ((b)->n_keys = (b)->n_nodes = 0, (b)->root = 0)
|
||||||
#define kb_destroy(name, b) __kb_destroy(kbnode_##name##_t, b)
|
#define kb_destroy(name, b) __kb_destroy(kbnode_##name##_t, b)
|
||||||
#define kb_get(name, b, k) kb_get_##name(b, k)
|
#define kb_get(name, b, k) kb_get_##name(b, k)
|
||||||
#define kb_put(name, b, k) kb_put_##name(b, k)
|
#define kb_put(name, b, k) kb_put_##name(b, k)
|
||||||
|
@ -888,9 +888,13 @@ void ex_changes(exarg_T *eap)
|
|||||||
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
|
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
|
||||||
* or: mark_adjust(56, 55, MAXLNUM, 2);
|
* or: mark_adjust(56, 55, MAXLNUM, 2);
|
||||||
*/
|
*/
|
||||||
void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
|
void mark_adjust(linenr_T line1,
|
||||||
|
linenr_T line2,
|
||||||
|
long amount,
|
||||||
|
long amount_after,
|
||||||
|
bool end_temp)
|
||||||
{
|
{
|
||||||
mark_adjust_internal(line1, line2, amount, amount_after, true);
|
mark_adjust_internal(line1, line2, amount, amount_after, true, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark_adjust_nofold() does the same as mark_adjust() but without adjusting
|
// mark_adjust_nofold() does the same as mark_adjust() but without adjusting
|
||||||
@ -899,13 +903,14 @@ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
|
|||||||
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
|
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
|
||||||
// for an example of why this may be necessary, see do_move().
|
// for an example of why this may be necessary, see do_move().
|
||||||
void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
|
void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
|
||||||
long amount_after)
|
long amount_after, bool end_temp)
|
||||||
{
|
{
|
||||||
mark_adjust_internal(line1, line2, amount, amount_after, false);
|
mark_adjust_internal(line1, line2, amount, amount_after, false, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount,
|
static void mark_adjust_internal(linenr_T line1, linenr_T line2,
|
||||||
long amount_after, bool adjust_folds)
|
long amount, long amount_after,
|
||||||
|
bool adjust_folds, bool end_temp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int fnum = curbuf->b_fnum;
|
int fnum = curbuf->b_fnum;
|
||||||
@ -954,7 +959,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sign_mark_adjust(line1, line2, amount, amount_after);
|
sign_mark_adjust(line1, line2, amount, amount_after);
|
||||||
bufhl_mark_adjust(curbuf, line1, line2, amount, amount_after);
|
bufhl_mark_adjust(curbuf, line1, line2, amount, amount_after, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* previous context mark */
|
/* previous context mark */
|
||||||
|
@ -751,7 +751,7 @@ open_line (
|
|||||||
// Skip mark_adjust when adding a line after the last one, there can't
|
// Skip mark_adjust when adding a line after the last one, there can't
|
||||||
// be marks there.
|
// be marks there.
|
||||||
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) {
|
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
|
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, false);
|
||||||
}
|
}
|
||||||
did_append = true;
|
did_append = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1866,7 +1866,7 @@ void appended_lines_mark(linenr_T lnum, long count)
|
|||||||
// Skip mark_adjust when adding a line after the last one, there can't
|
// Skip mark_adjust when adding a line after the last one, there can't
|
||||||
// be marks there.
|
// be marks there.
|
||||||
if (lnum + count < curbuf->b_ml.ml_line_count) {
|
if (lnum + count < curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
|
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, false);
|
||||||
}
|
}
|
||||||
changed_lines(lnum + 1, 0, lnum + 1, count);
|
changed_lines(lnum + 1, 0, lnum + 1, count);
|
||||||
}
|
}
|
||||||
@ -1888,7 +1888,7 @@ void deleted_lines(linenr_T lnum, long count)
|
|||||||
*/
|
*/
|
||||||
void deleted_lines_mark(linenr_T lnum, long count)
|
void deleted_lines_mark(linenr_T lnum, long count)
|
||||||
{
|
{
|
||||||
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count);
|
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count, false);
|
||||||
changed_lines(lnum, 0, lnum + count, -count);
|
changed_lines(lnum, 0, lnum + count, -count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3182,7 +3182,7 @@ error:
|
|||||||
if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines
|
if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines
|
||||||
< curbuf->b_ml.ml_line_count) {
|
< curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
|
mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
|
||||||
(linenr_T)MAXLNUM, nr_lines, 0L);
|
(linenr_T)MAXLNUM, nr_lines, 0L, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// note changed text for displaying and folding
|
// note changed text for displaying and folding
|
||||||
|
@ -2232,12 +2232,14 @@ static void u_undoredo(int undo)
|
|||||||
/* adjust marks */
|
/* adjust marks */
|
||||||
if (oldsize != newsize) {
|
if (oldsize != newsize) {
|
||||||
mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
|
mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
|
||||||
(long)newsize - (long)oldsize);
|
(long)newsize - (long)oldsize, false);
|
||||||
if (curbuf->b_op_start.lnum > top + oldsize)
|
if (curbuf->b_op_start.lnum > top + oldsize) {
|
||||||
curbuf->b_op_start.lnum += newsize - oldsize;
|
curbuf->b_op_start.lnum += newsize - oldsize;
|
||||||
if (curbuf->b_op_end.lnum > top + oldsize)
|
}
|
||||||
|
if (curbuf->b_op_end.lnum > top + oldsize) {
|
||||||
curbuf->b_op_end.lnum += newsize - oldsize;
|
curbuf->b_op_end.lnum += newsize - oldsize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
changed_lines(top + 1, 0, bot, newsize - oldsize);
|
changed_lines(top + 1, 0, bot, newsize - oldsize);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user