aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/misc1.c
diff options
context:
space:
mode:
authorPeter Hodge <peter.hodge84@gmail.com>2018-01-26 20:36:11 +0100
committerKillTheMule <KillTheMule@users.noreply.github.com>2018-05-23 22:07:27 +0200
commitedcc73e766438facc88db19000f054aa52ab8b13 (patch)
tree17a62cbbb7785e6f88aaa99728cfa0d8cd5e076c /src/nvim/misc1.c
parent418abfc9d06923e96f1317419fe83ed4e6d67c1d (diff)
downloadrneovim-edcc73e766438facc88db19000f054aa52ab8b13.tar.gz
rneovim-edcc73e766438facc88db19000f054aa52ab8b13.tar.bz2
rneovim-edcc73e766438facc88db19000f054aa52ab8b13.zip
API: Implement buffer updates
Originally written by @phodge in https://github.com/neovim/neovim/pull/5269.
Diffstat (limited to 'src/nvim/misc1.c')
-rw-r--r--src/nvim/misc1.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 28455f0ba9..a3b2d5e7a4 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -28,6 +28,7 @@
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
+#include "nvim/liveupdate.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
@@ -835,7 +836,7 @@ open_line (
saved_line = NULL;
if (did_append) {
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
- curwin->w_cursor.lnum + 1, 1L);
+ curwin->w_cursor.lnum + 1, 1L, true);
did_append = FALSE;
/* Move marks after the line break to the new line. */
@@ -853,8 +854,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;
@@ -1819,6 +1821,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->liveupdate_channels)) {
+ liveupdate_send_changes(curbuf, lnum, 1, 1, true);
+ }
/* Diff highlighting in other diff windows may need to be updated too. */
if (curwin->w_p_diff) {
@@ -1859,7 +1865,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);
}
/*
@@ -1872,7 +1878,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);
}
/*
@@ -1882,7 +1888,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);
}
/*
@@ -1893,7 +1899,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);
}
/*
@@ -1913,7 +1919,11 @@ 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) */
+ long xtra, /* number of extra lines (negative when deleting) */
+ bool send_liveupdate // some callers like undo/redo call changed_lines()
+ // and then increment b_changedtick *again*. This flag
+ // allows these callers to send the LiveUpdate events
+ // after they're done modifying b_changedtick.
)
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
@@ -1937,6 +1947,12 @@ changed_lines (
}
changed_common(lnum, col, lnume, xtra);
+
+ if (send_liveupdate && kv_size(curbuf->liveupdate_channels)) {
+ int64_t num_added = (int64_t)(lnume + xtra - lnum);
+ int64_t num_removed = lnume - lnum;
+ liveupdate_send_changes(curbuf, lnum, num_added, num_removed, true);
+ }
}
/// Mark line range in buffer as changed.