mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 12:08:33 +00:00
Merge #7917 'API: buffer updates'
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/indent.h"
|
||||
#include "nvim/indent_c.h"
|
||||
#include "nvim/buffer_updates.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/mark.h"
|
||||
#include "nvim/mbyte.h"
|
||||
@@ -836,8 +837,8 @@ open_line (
|
||||
saved_line = NULL;
|
||||
if (did_append) {
|
||||
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
||||
curwin->w_cursor.lnum + 1, 1L);
|
||||
did_append = FALSE;
|
||||
curwin->w_cursor.lnum + 1, 1L, true);
|
||||
did_append = false;
|
||||
|
||||
/* Move marks after the line break to the new line. */
|
||||
if (flags & OPENLINE_MARKFIX)
|
||||
@@ -854,8 +855,9 @@ open_line (
|
||||
*/
|
||||
curwin->w_cursor.lnum = old_cursor.lnum + 1;
|
||||
}
|
||||
if (did_append)
|
||||
changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L);
|
||||
if (did_append) {
|
||||
changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true);
|
||||
}
|
||||
|
||||
curwin->w_cursor.col = newcol;
|
||||
curwin->w_cursor.coladd = 0;
|
||||
@@ -1820,6 +1822,10 @@ void changed_bytes(linenr_T lnum, colnr_T col)
|
||||
{
|
||||
changedOneline(curbuf, lnum);
|
||||
changed_common(lnum, col, lnum + 1, 0L);
|
||||
// notify any channels that are watching
|
||||
if (kv_size(curbuf->update_channels)) {
|
||||
buf_updates_send_changes(curbuf, lnum, 1, 1, true);
|
||||
}
|
||||
|
||||
/* Diff highlighting in other diff windows may need to be updated too. */
|
||||
if (curwin->w_p_diff) {
|
||||
@@ -1860,7 +1866,7 @@ static void changedOneline(buf_T *buf, linenr_T lnum)
|
||||
*/
|
||||
void appended_lines(linenr_T lnum, long count)
|
||||
{
|
||||
changed_lines(lnum + 1, 0, lnum + 1, count);
|
||||
changed_lines(lnum + 1, 0, lnum + 1, count, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1873,7 +1879,7 @@ void appended_lines_mark(linenr_T lnum, long count)
|
||||
if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) {
|
||||
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, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1883,7 +1889,7 @@ void appended_lines_mark(linenr_T lnum, long count)
|
||||
*/
|
||||
void deleted_lines(linenr_T lnum, long count)
|
||||
{
|
||||
changed_lines(lnum, 0, lnum + count, -count);
|
||||
changed_lines(lnum, 0, lnum + count, -count, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1894,7 +1900,7 @@ void deleted_lines(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, false);
|
||||
changed_lines(lnum, 0, lnum + count, -count);
|
||||
changed_lines(lnum, 0, lnum + count, -count, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1909,12 +1915,16 @@ void deleted_lines_mark(linenr_T lnum, long count)
|
||||
* Takes care of calling changed() and updating b_mod_*.
|
||||
* Careful: may trigger autocommands that reload the buffer.
|
||||
*/
|
||||
void
|
||||
changed_lines (
|
||||
linenr_T lnum, /* first line with change */
|
||||
colnr_T col, /* column in first line with change */
|
||||
linenr_T lnume, /* line below last changed line */
|
||||
long xtra /* number of extra lines (negative when deleting) */
|
||||
void
|
||||
changed_lines(
|
||||
linenr_T lnum, // first line with change
|
||||
colnr_T col, // column in first line with change
|
||||
linenr_T lnume, // line below last changed line
|
||||
long xtra, // number of extra lines (negative when deleting)
|
||||
bool do_buf_event // some callers like undo/redo call changed_lines()
|
||||
// and then increment b_changedtick *again*. This flag
|
||||
// allows these callers to send the nvim_buf_lines_event
|
||||
// events after they're done modifying b_changedtick.
|
||||
)
|
||||
{
|
||||
changed_lines_buf(curbuf, lnum, lnume, xtra);
|
||||
@@ -1938,6 +1948,12 @@ changed_lines (
|
||||
}
|
||||
|
||||
changed_common(lnum, col, lnume, xtra);
|
||||
|
||||
if (do_buf_event && kv_size(curbuf->update_channels)) {
|
||||
int64_t num_added = (int64_t)(lnume + xtra - lnum);
|
||||
int64_t num_removed = lnume - lnum;
|
||||
buf_updates_send_changes(curbuf, lnum, num_added, num_removed, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark line range in buffer as changed.
|
||||
|
Reference in New Issue
Block a user