mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
API: Implement buffer updates
Originally written by @phodge in https://github.com/neovim/neovim/pull/5269.
This commit is contained in:
parent
418abfc9d0
commit
edcc73e766
@ -142,6 +142,7 @@ set(CONV_SOURCES
|
|||||||
message.c
|
message.c
|
||||||
regexp.c
|
regexp.c
|
||||||
screen.c
|
screen.c
|
||||||
|
liveupdate.c
|
||||||
search.c
|
search.c
|
||||||
spell.c
|
spell.c
|
||||||
spellfile.c
|
spellfile.c
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/undo.h"
|
#include "nvim/undo.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "api/buffer.c.generated.h"
|
# include "api/buffer.c.generated.h"
|
||||||
@ -75,6 +76,34 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Activate live updates from this buffer to the current channel.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @param buffer The buffer handle
|
||||||
|
/// @param enabled True turns on live updates, False turns them off.
|
||||||
|
/// @param[out] err Details of an error that may have occurred
|
||||||
|
/// @return False when live updates couldn't be enabled because the buffer isn't
|
||||||
|
/// loaded; otherwise True.
|
||||||
|
Boolean nvim_buf_live_updates(uint64_t channel_id,
|
||||||
|
Buffer buffer,
|
||||||
|
Boolean enabled,
|
||||||
|
Error *err)
|
||||||
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY
|
||||||
|
{
|
||||||
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
return liveupdate_register(buf, channel_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
liveupdate_unregister(buf, channel_id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets a buffer line
|
/// Sets a buffer line
|
||||||
///
|
///
|
||||||
/// @deprecated use nvim_buf_set_lines instead.
|
/// @deprecated use nvim_buf_set_lines instead.
|
||||||
@ -407,7 +436,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
|
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true);
|
||||||
|
|
||||||
if (save_curbuf.br_buf == NULL) {
|
if (save_curbuf.br_buf == NULL) {
|
||||||
fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra);
|
fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra);
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os/input.h"
|
#include "nvim/os/input.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kBLSUnchanged = 0,
|
kBLSUnchanged = 0,
|
||||||
@ -574,6 +575,9 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
|
|||||||
/* Change directories when the 'acd' option is set. */
|
/* Change directories when the 'acd' option is set. */
|
||||||
do_autochdir();
|
do_autochdir();
|
||||||
|
|
||||||
|
// disable live updates for the current buffer
|
||||||
|
liveupdate_unregister_all(buf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove the buffer from the list.
|
* Remove the buffer from the list.
|
||||||
*/
|
*/
|
||||||
@ -784,6 +788,8 @@ free_buffer_stuff (
|
|||||||
map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs
|
map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs
|
||||||
xfree(buf->b_start_fenc);
|
xfree(buf->b_start_fenc);
|
||||||
buf->b_start_fenc = NULL;
|
buf->b_start_fenc = NULL;
|
||||||
|
|
||||||
|
liveupdate_unregister_all(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1735,6 +1741,8 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
|
|||||||
clrallmarks(buf); /* clear marks */
|
clrallmarks(buf); /* clear marks */
|
||||||
fmarks_check_names(buf); /* check file marks for this file */
|
fmarks_check_names(buf); /* check file marks for this file */
|
||||||
buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */
|
buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */
|
||||||
|
kv_destroy(buf->liveupdate_channels);
|
||||||
|
kv_init(buf->liveupdate_channels);
|
||||||
if (!(flags & BLN_DUMMY)) {
|
if (!(flags & BLN_DUMMY)) {
|
||||||
// Tricky: these autocommands may change the buffer list. They could also
|
// Tricky: these autocommands may change the buffer list. They could also
|
||||||
// split the window with re-using the one empty buffer. This may result in
|
// split the window with re-using the one empty buffer. This may result in
|
||||||
|
@ -38,6 +38,8 @@ typedef struct {
|
|||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
// for Map(K, V)
|
// for Map(K, V)
|
||||||
#include "nvim/map.h"
|
#include "nvim/map.h"
|
||||||
|
// for kvec
|
||||||
|
#include "nvim/lib/kvec.h"
|
||||||
|
|
||||||
#define MODIFIABLE(buf) (buf->b_p_ma)
|
#define MODIFIABLE(buf) (buf->b_p_ma)
|
||||||
|
|
||||||
@ -771,6 +773,10 @@ struct file_buffer {
|
|||||||
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
|
kvec_t(BufhlLine *) b_bufhl_move_space; // temporary space for highlights
|
||||||
|
|
||||||
|
// array of channelids which have asked to receive live updates for this
|
||||||
|
// buffer.
|
||||||
|
kvec_t(uint64_t) liveupdate_channels;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2344,7 +2344,7 @@ void ex_diffgetput(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changed_lines(lnum, 0, lnum + count, (long)added);
|
changed_lines(lnum, 0, lnum + count, (long)added, true);
|
||||||
|
|
||||||
if (dfree != NULL) {
|
if (dfree != NULL) {
|
||||||
// Diff is deleted, update folds in other windows.
|
// Diff is deleted, update folds in other windows.
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
#include "nvim/main.h"
|
#include "nvim/main.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
@ -279,7 +280,7 @@ void ex_align(exarg_T *eap)
|
|||||||
new_indent = 0;
|
new_indent = 0;
|
||||||
(void)set_indent(new_indent, 0); /* set indent */
|
(void)set_indent(new_indent, 0); /* set indent */
|
||||||
}
|
}
|
||||||
changed_lines(eap->line1, 0, eap->line2 + 1, 0L);
|
changed_lines(eap->line1, 0, eap->line2 + 1, 0L, true);
|
||||||
curwin->w_cursor = save_curpos;
|
curwin->w_cursor = save_curpos;
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
}
|
}
|
||||||
@ -612,7 +613,7 @@ void ex_sort(exarg_T *eap)
|
|||||||
} else if (deleted < 0) {
|
} else if (deleted < 0) {
|
||||||
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, false);
|
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, true);
|
||||||
|
|
||||||
curwin->w_cursor.lnum = eap->line1;
|
curwin->w_cursor.lnum = eap->line1;
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
@ -745,7 +746,7 @@ void ex_retab(exarg_T *eap)
|
|||||||
if (curbuf->b_p_ts != new_ts)
|
if (curbuf->b_p_ts != new_ts)
|
||||||
redraw_curbuf_later(NOT_VALID);
|
redraw_curbuf_later(NOT_VALID);
|
||||||
if (first_line != 0)
|
if (first_line != 0)
|
||||||
changed_lines(first_line, 0, last_line + 1, 0L);
|
changed_lines(first_line, 0, last_line + 1, 0L, true);
|
||||||
|
|
||||||
curwin->w_p_list = save_list; /* restore 'list' */
|
curwin->w_p_list = save_list; /* restore 'list' */
|
||||||
|
|
||||||
@ -806,6 +807,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
*/
|
*/
|
||||||
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, true);
|
mark_adjust_nofold(line1, line2, last_line - line2, 0L, true);
|
||||||
|
changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines, false);
|
||||||
if (dest >= line2) {
|
if (dest >= line2) {
|
||||||
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L, false);
|
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L, false);
|
||||||
FOR_ALL_TAB_WINDOWS(tab, win) {
|
FOR_ALL_TAB_WINDOWS(tab, win) {
|
||||||
@ -828,6 +830,12 @@ 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, true);
|
-(last_line - dest - extra), 0L, true);
|
||||||
|
changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra, false);
|
||||||
|
|
||||||
|
// send live update regarding the new lines that were added
|
||||||
|
if (kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
liveupdate_send_changes(curbuf, dest + 1, num_lines, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we delete the original text -- webb
|
* Now we delete the original text -- webb
|
||||||
@ -858,9 +866,14 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
last_line = curbuf->b_ml.ml_line_count;
|
last_line = curbuf->b_ml.ml_line_count;
|
||||||
if (dest > last_line + 1)
|
if (dest > last_line + 1)
|
||||||
dest = last_line + 1;
|
dest = last_line + 1;
|
||||||
changed_lines(line1, 0, dest, 0L);
|
changed_lines(line1, 0, dest, 0L, false);
|
||||||
} else {
|
} else {
|
||||||
changed_lines(dest + 1, 0, line1 + num_lines, 0L);
|
changed_lines(dest + 1, 0, line1 + num_lines, 0L, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send LiveUpdate regarding lines that were deleted
|
||||||
|
if (kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
liveupdate_send_changes(curbuf, line1 + extra, 0, num_lines, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@ -2428,6 +2441,7 @@ int do_ecmd(
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
u_unchanged(curbuf);
|
u_unchanged(curbuf);
|
||||||
|
liveupdate_unregister_all(curbuf);
|
||||||
buf_freeall(curbuf, BFA_KEEP_UNDO);
|
buf_freeall(curbuf, BFA_KEEP_UNDO);
|
||||||
|
|
||||||
// Tell readfile() not to clear or reload undo info.
|
// Tell readfile() not to clear or reload undo info.
|
||||||
@ -3154,7 +3168,8 @@ static char_u *sub_parse_flags(char_u *cmd, subflags_T *subflags,
|
|||||||
/// The usual escapes are supported as described in the regexp docs.
|
/// The usual escapes are supported as described in the regexp docs.
|
||||||
///
|
///
|
||||||
/// @return buffer used for 'inccommand' preview
|
/// @return buffer used for 'inccommand' preview
|
||||||
static buf_T *do_sub(exarg_T *eap, proftime_T timeout)
|
static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
||||||
|
bool send_liveupdate_changedtick)
|
||||||
{
|
{
|
||||||
long i = 0;
|
long i = 0;
|
||||||
regmmatch_T regmatch;
|
regmmatch_T regmatch;
|
||||||
@ -4000,7 +4015,14 @@ skip:
|
|||||||
* the line number before the change (same as adding the number of
|
* the line number before the change (same as adding the number of
|
||||||
* deleted lines). */
|
* deleted lines). */
|
||||||
i = curbuf->b_ml.ml_line_count - old_line_count;
|
i = curbuf->b_ml.ml_line_count - old_line_count;
|
||||||
changed_lines(first_line, 0, last_line - i, i);
|
changed_lines(first_line, 0, last_line - i, i, false);
|
||||||
|
|
||||||
|
if (kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
int64_t num_added = last_line - first_line;
|
||||||
|
int64_t num_removed = num_added - i;
|
||||||
|
liveupdate_send_changes(curbuf, first_line, num_added, num_removed,
|
||||||
|
send_liveupdate_changedtick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree(sub_firstline); /* may have to free allocated copy of the line */
|
xfree(sub_firstline); /* may have to free allocated copy of the line */
|
||||||
@ -6246,7 +6268,7 @@ void ex_substitute(exarg_T *eap)
|
|||||||
{
|
{
|
||||||
bool preview = (State & CMDPREVIEW);
|
bool preview = (State & CMDPREVIEW);
|
||||||
if (*p_icm == NUL || !preview) { // 'inccommand' is disabled
|
if (*p_icm == NUL || !preview) { // 'inccommand' is disabled
|
||||||
(void)do_sub(eap, profile_zero());
|
(void)do_sub(eap, profile_zero(), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6270,7 +6292,7 @@ void ex_substitute(exarg_T *eap)
|
|||||||
// Don't show search highlighting during live substitution
|
// Don't show search highlighting during live substitution
|
||||||
bool save_hls = p_hls;
|
bool save_hls = p_hls;
|
||||||
p_hls = false;
|
p_hls = false;
|
||||||
buf_T *preview_buf = do_sub(eap, profile_setlimit(p_rdt));
|
buf_T *preview_buf = do_sub(eap, profile_setlimit(p_rdt), false);
|
||||||
p_hls = save_hls;
|
p_hls = save_hls;
|
||||||
|
|
||||||
if (save_changedtick != curbuf->b_changedtick) {
|
if (save_changedtick != curbuf->b_changedtick) {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
@ -742,8 +743,20 @@ deleteFold (
|
|||||||
/* Deleting markers may make cursor column invalid. */
|
/* Deleting markers may make cursor column invalid. */
|
||||||
check_cursor_col();
|
check_cursor_col();
|
||||||
|
|
||||||
if (last_lnum > 0)
|
if (last_lnum > 0) {
|
||||||
changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L);
|
changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L, false);
|
||||||
|
|
||||||
|
// send one LiveUpdate at the end
|
||||||
|
if (kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
// last_lnum is the line *after* the last line of the outermost fold
|
||||||
|
// that was modified. Note also that deleting a fold might only require
|
||||||
|
// the modification of the *first* line of the fold, but we send through a
|
||||||
|
// notification that includes every line that was part of the fold
|
||||||
|
int64_t num_changed = last_lnum - first_lnum;
|
||||||
|
liveupdate_send_changes(curbuf, first_lnum, num_changed,
|
||||||
|
num_changed, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clearFolding() {{{2 */
|
/* clearFolding() {{{2 */
|
||||||
@ -1590,7 +1603,15 @@ static void foldCreateMarkers(linenr_T start, linenr_T end)
|
|||||||
|
|
||||||
/* Update both changes here, to avoid all folds after the start are
|
/* Update both changes here, to avoid all folds after the start are
|
||||||
* changed when the start marker is inserted and the end isn't. */
|
* changed when the start marker is inserted and the end isn't. */
|
||||||
changed_lines(start, (colnr_T)0, end, 0L);
|
changed_lines(start, (colnr_T)0, end, 0L, false);
|
||||||
|
|
||||||
|
if (kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
// Note: foldAddMarker() may not actually change start and/or end if
|
||||||
|
// u_save() is unable to save the buffer line, but we send the LiveUpdate
|
||||||
|
// anyway since it won't do any harm.
|
||||||
|
int64_t num_changed = 1 + end - start;
|
||||||
|
liveupdate_send_changes(curbuf, start, num_changed, num_changed, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* foldAddMarker() {{{2 */
|
/* foldAddMarker() {{{2 */
|
||||||
|
195
src/nvim/liveupdate.c
Normal file
195
src/nvim/liveupdate.c
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
#include "nvim/liveupdate.h"
|
||||||
|
#include "nvim/memline.h"
|
||||||
|
#include "nvim/api/private/helpers.h"
|
||||||
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
|
|
||||||
|
// Register a channel. Return True if the channel was added, or already added.
|
||||||
|
// Return False if the channel couldn't be added because the buffer is
|
||||||
|
// unloaded.
|
||||||
|
bool liveupdate_register(buf_T *buf, uint64_t channel_id)
|
||||||
|
{
|
||||||
|
// must fail if the buffer isn't loaded
|
||||||
|
if (buf->b_ml.ml_mfp == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// count how many channels are currently watching the buffer
|
||||||
|
size_t size = kv_size(buf->liveupdate_channels);
|
||||||
|
if (size) {
|
||||||
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
if (kv_A(buf->liveupdate_channels, i) == channel_id) {
|
||||||
|
// buffer is already registered ... nothing to do
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// append the channelid to the list
|
||||||
|
kv_push(buf->liveupdate_channels, channel_id);
|
||||||
|
|
||||||
|
// send through the full channel contents now
|
||||||
|
Array linedata = ARRAY_DICT_INIT;
|
||||||
|
size_t line_count = buf->b_ml.ml_line_count;
|
||||||
|
linedata.size = line_count;
|
||||||
|
linedata.items = xcalloc(sizeof(Object), line_count);
|
||||||
|
for (size_t i = 0; i < line_count; i++) {
|
||||||
|
linenr_T lnum = 1 + (linenr_T)i;
|
||||||
|
|
||||||
|
const char *bufstr = (char *)ml_get_buf(buf, lnum, false);
|
||||||
|
Object str = STRING_OBJ(cstr_to_string(bufstr));
|
||||||
|
|
||||||
|
// Vim represents NULs as NLs, but this may confuse clients.
|
||||||
|
strchrsub(str.data.string.data, '\n', '\0');
|
||||||
|
|
||||||
|
linedata.items[i] = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
args.size = 4;
|
||||||
|
args.items = xcalloc(sizeof(Object), args.size);
|
||||||
|
|
||||||
|
// the first argument is always the buffer handle
|
||||||
|
args.items[0] = BUFFER_OBJ(buf->handle);
|
||||||
|
args.items[1] = INTEGER_OBJ(buf->b_changedtick);
|
||||||
|
args.items[2] = ARRAY_OBJ(linedata);
|
||||||
|
args.items[3] = BOOLEAN_OBJ(false);
|
||||||
|
|
||||||
|
channel_send_event(channel_id, "LiveUpdateStart", args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void liveupdate_send_end(buf_T *buf, uint64_t channelid)
|
||||||
|
{
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
args.size = 1;
|
||||||
|
args.items = xcalloc(sizeof(Object), args.size);
|
||||||
|
args.items[0] = BUFFER_OBJ(buf->handle);
|
||||||
|
channel_send_event(channelid, "LiveUpdateEnd", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void liveupdate_unregister(buf_T *buf, uint64_t channelid)
|
||||||
|
{
|
||||||
|
size_t size = kv_size(buf->liveupdate_channels);
|
||||||
|
if (!size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// go through list backwards and remove the channel id each time it appears
|
||||||
|
// (it should never appear more than once)
|
||||||
|
size_t j = 0;
|
||||||
|
size_t found = 0;
|
||||||
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
if (kv_A(buf->liveupdate_channels, i) == channelid) {
|
||||||
|
found++;
|
||||||
|
} else {
|
||||||
|
// copy item backwards into prior slot if needed
|
||||||
|
if (i != j) {
|
||||||
|
kv_A(buf->liveupdate_channels, j) = kv_A(buf->liveupdate_channels, i);
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
// remove X items from the end of the array
|
||||||
|
buf->liveupdate_channels.size -= found;
|
||||||
|
|
||||||
|
// make a new copy of the active array without the channelid in it
|
||||||
|
liveupdate_send_end(buf, channelid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void liveupdate_unregister_all(buf_T *buf)
|
||||||
|
{
|
||||||
|
size_t size = kv_size(buf->liveupdate_channels);
|
||||||
|
if (size) {
|
||||||
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
liveupdate_send_end(buf, kv_A(buf->liveupdate_channels, i));
|
||||||
|
}
|
||||||
|
kv_destroy(buf->liveupdate_channels);
|
||||||
|
kv_init(buf->liveupdate_channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void liveupdate_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
|
||||||
|
int64_t num_removed, bool send_tick)
|
||||||
|
{
|
||||||
|
// if one the channels doesn't work, put its ID here so we can remove it later
|
||||||
|
uint64_t badchannelid = 0;
|
||||||
|
|
||||||
|
// notify each of the active channels
|
||||||
|
for (size_t i = 0; i < kv_size(buf->liveupdate_channels); i++) {
|
||||||
|
uint64_t channelid = kv_A(buf->liveupdate_channels, i);
|
||||||
|
|
||||||
|
// send through the changes now channel contents now
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
args.size = 5;
|
||||||
|
args.items = xcalloc(sizeof(Object), args.size);
|
||||||
|
|
||||||
|
// the first argument is always the buffer handle
|
||||||
|
args.items[0] = BUFFER_OBJ(buf->handle);
|
||||||
|
|
||||||
|
// next argument is b:changedtick
|
||||||
|
args.items[1] = send_tick ? INTEGER_OBJ(buf->b_changedtick) : NIL;
|
||||||
|
|
||||||
|
// the first line that changed (zero-indexed)
|
||||||
|
args.items[2] = INTEGER_OBJ(firstline - 1);
|
||||||
|
|
||||||
|
// how many lines are being swapped out
|
||||||
|
args.items[3] = INTEGER_OBJ(num_removed);
|
||||||
|
|
||||||
|
// linedata of lines being swapped in
|
||||||
|
Array linedata = ARRAY_DICT_INIT;
|
||||||
|
if (num_added > 0) {
|
||||||
|
linedata.size = num_added;
|
||||||
|
linedata.items = xcalloc(sizeof(Object), num_added);
|
||||||
|
for (int64_t i = 0; i < num_added; i++) {
|
||||||
|
int64_t lnum = firstline + i;
|
||||||
|
const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
|
||||||
|
Object str = STRING_OBJ(cstr_to_string(bufstr));
|
||||||
|
|
||||||
|
// Vim represents NULs as NLs, but this may confuse clients.
|
||||||
|
strchrsub(str.data.string.data, '\n', '\0');
|
||||||
|
|
||||||
|
linedata.items[i] = str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args.items[4] = ARRAY_OBJ(linedata);
|
||||||
|
if (!channel_send_event(channelid, "LiveUpdate", args)) {
|
||||||
|
// We can't unregister the channel while we're iterating over the
|
||||||
|
// liveupdate_channels array, so we remember its ID to unregister it at
|
||||||
|
// the end.
|
||||||
|
badchannelid = channelid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can only ever remove one dead channel at a time. This is OK because the
|
||||||
|
// change notifications are so frequent that many dead channels will be
|
||||||
|
// cleared up quickly.
|
||||||
|
if (badchannelid != 0) {
|
||||||
|
ELOG("Disabling live updates for dead channel %llu", badchannelid);
|
||||||
|
liveupdate_unregister(buf, badchannelid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void liveupdate_send_tick(buf_T *buf)
|
||||||
|
{
|
||||||
|
// notify each of the active channels
|
||||||
|
for (size_t i = 0; i < kv_size(buf->liveupdate_channels); i++) {
|
||||||
|
uint64_t channelid = kv_A(buf->liveupdate_channels, i);
|
||||||
|
|
||||||
|
// send through the changes now channel contents now
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
args.size = 2;
|
||||||
|
args.items = xcalloc(sizeof(Object), args.size);
|
||||||
|
|
||||||
|
// the first argument is always the buffer handle
|
||||||
|
args.items[0] = BUFFER_OBJ(buf->handle);
|
||||||
|
|
||||||
|
// next argument is b:changedtick
|
||||||
|
args.items[1] = INTEGER_OBJ(buf->b_changedtick);
|
||||||
|
|
||||||
|
// don't try and clean up dead channels here
|
||||||
|
channel_send_event(channelid, "LiveUpdateTick", args);
|
||||||
|
}
|
||||||
|
}
|
13
src/nvim/liveupdate.h
Normal file
13
src/nvim/liveupdate.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef NVIM_LIVEUPDATE_H
|
||||||
|
#define NVIM_LIVEUPDATE_H
|
||||||
|
|
||||||
|
#include "nvim/buffer_defs.h"
|
||||||
|
|
||||||
|
bool liveupdate_register(buf_T *buf, uint64_t channel_id);
|
||||||
|
void liveupdate_unregister(buf_T *buf, uint64_t channel_id);
|
||||||
|
void liveupdate_unregister_all(buf_T *buf);
|
||||||
|
void liveupdate_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
|
||||||
|
int64_t num_removed, bool send_tick);
|
||||||
|
void liveupdate_send_tick(buf_T *buf);
|
||||||
|
|
||||||
|
#endif // NVIM_LIVEUPDATE_H
|
@ -28,6 +28,7 @@
|
|||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
#include "nvim/indent_c.h"
|
#include "nvim/indent_c.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
#include "nvim/main.h"
|
#include "nvim/main.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
@ -835,7 +836,7 @@ open_line (
|
|||||||
saved_line = NULL;
|
saved_line = NULL;
|
||||||
if (did_append) {
|
if (did_append) {
|
||||||
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
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;
|
did_append = FALSE;
|
||||||
|
|
||||||
/* Move marks after the line break to the new line. */
|
/* Move marks after the line break to the new line. */
|
||||||
@ -853,8 +854,9 @@ open_line (
|
|||||||
*/
|
*/
|
||||||
curwin->w_cursor.lnum = old_cursor.lnum + 1;
|
curwin->w_cursor.lnum = old_cursor.lnum + 1;
|
||||||
}
|
}
|
||||||
if (did_append)
|
if (did_append) {
|
||||||
changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L);
|
changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true);
|
||||||
|
}
|
||||||
|
|
||||||
curwin->w_cursor.col = newcol;
|
curwin->w_cursor.col = newcol;
|
||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
@ -1819,6 +1821,10 @@ void changed_bytes(linenr_T lnum, colnr_T col)
|
|||||||
{
|
{
|
||||||
changedOneline(curbuf, lnum);
|
changedOneline(curbuf, lnum);
|
||||||
changed_common(lnum, col, lnum + 1, 0L);
|
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. */
|
/* Diff highlighting in other diff windows may need to be updated too. */
|
||||||
if (curwin->w_p_diff) {
|
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)
|
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) {
|
if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) {
|
||||||
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, false);
|
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)
|
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)
|
void deleted_lines_mark(linenr_T lnum, long count)
|
||||||
{
|
{
|
||||||
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count, false);
|
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 */
|
linenr_T lnum, /* first line with change */
|
||||||
colnr_T col, /* column in first line with change */
|
colnr_T col, /* column in first line with change */
|
||||||
linenr_T lnume, /* line below last changed line */
|
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);
|
changed_lines_buf(curbuf, lnum, lnume, xtra);
|
||||||
@ -1937,6 +1947,12 @@ changed_lines (
|
|||||||
}
|
}
|
||||||
|
|
||||||
changed_common(lnum, col, lnume, xtra);
|
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.
|
/// Mark line range in buffer as changed.
|
||||||
|
@ -6140,7 +6140,7 @@ static void n_swapchar(cmdarg_T *cap)
|
|||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
if (did_change) {
|
if (did_change) {
|
||||||
changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1,
|
changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1,
|
||||||
0L);
|
0L, true);
|
||||||
curbuf->b_op_start = startpos;
|
curbuf->b_op_start = startpos;
|
||||||
curbuf->b_op_end = curwin->w_cursor;
|
curbuf->b_op_end = curwin->w_cursor;
|
||||||
if (curbuf->b_op_end.col > 0)
|
if (curbuf->b_op_end.col > 0)
|
||||||
|
@ -214,7 +214,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
|
|||||||
++curwin->w_cursor.lnum;
|
++curwin->w_cursor.lnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true);
|
||||||
|
|
||||||
if (oap->motion_type == kMTBlockWise) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
curwin->w_cursor.lnum = oap->start.lnum;
|
curwin->w_cursor.lnum = oap->start.lnum;
|
||||||
@ -570,7 +570,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
|
|||||||
}
|
}
|
||||||
} /* for all lnum */
|
} /* for all lnum */
|
||||||
|
|
||||||
changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true);
|
||||||
|
|
||||||
State = oldstate;
|
State = oldstate;
|
||||||
}
|
}
|
||||||
@ -634,8 +634,8 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
* there is no change still need to remove the Visual highlighting. */
|
* there is no change still need to remove the Visual highlighting. */
|
||||||
if (last_changed != 0)
|
if (last_changed != 0)
|
||||||
changed_lines(first_changed, 0,
|
changed_lines(first_changed, 0,
|
||||||
oap->is_VIsual ? start_lnum + oap->line_count :
|
oap->is_VIsual ? start_lnum + oap->line_count :
|
||||||
last_changed + 1, 0L);
|
last_changed + 1, 0L, true);
|
||||||
else if (oap->is_VIsual)
|
else if (oap->is_VIsual)
|
||||||
redraw_curbuf_later(INVERTED);
|
redraw_curbuf_later(INVERTED);
|
||||||
|
|
||||||
@ -1455,7 +1455,7 @@ int op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
check_cursor_col();
|
check_cursor_col();
|
||||||
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
||||||
oap->end.lnum + 1, 0L);
|
oap->end.lnum + 1, 0L, true);
|
||||||
oap->line_count = 0; // no lines deleted
|
oap->line_count = 0; // no lines deleted
|
||||||
} else if (oap->motion_type == kMTLineWise) {
|
} else if (oap->motion_type == kMTLineWise) {
|
||||||
if (oap->op_type == OP_CHANGE) {
|
if (oap->op_type == OP_CHANGE) {
|
||||||
@ -1822,7 +1822,7 @@ int op_replace(oparg_T *oap, int c)
|
|||||||
|
|
||||||
curwin->w_cursor = oap->start;
|
curwin->w_cursor = oap->start;
|
||||||
check_cursor();
|
check_cursor();
|
||||||
changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L, true);
|
||||||
|
|
||||||
/* Set "'[" and "']" marks. */
|
/* Set "'[" and "']" marks. */
|
||||||
curbuf->b_op_start = oap->start;
|
curbuf->b_op_start = oap->start;
|
||||||
@ -1857,7 +1857,7 @@ void op_tilde(oparg_T *oap)
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (did_change)
|
if (did_change)
|
||||||
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true);
|
||||||
} else { // not block mode
|
} else { // not block mode
|
||||||
if (oap->motion_type == kMTLineWise) {
|
if (oap->motion_type == kMTLineWise) {
|
||||||
oap->start.col = 0;
|
oap->start.col = 0;
|
||||||
@ -1881,7 +1881,7 @@ void op_tilde(oparg_T *oap)
|
|||||||
}
|
}
|
||||||
if (did_change) {
|
if (did_change) {
|
||||||
changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
|
changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
|
||||||
0L);
|
0L, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2264,7 +2264,7 @@ int op_change(oparg_T *oap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_cursor();
|
check_cursor();
|
||||||
changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true);
|
||||||
xfree(ins_text);
|
xfree(ins_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3033,7 +3033,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
curwin->w_cursor.col += bd.startspaces;
|
curwin->w_cursor.col += bd.startspaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines);
|
changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines, true);
|
||||||
|
|
||||||
/* Set '[ mark. */
|
/* Set '[ mark. */
|
||||||
curbuf->b_op_start = curwin->w_cursor;
|
curbuf->b_op_start = curwin->w_cursor;
|
||||||
@ -3210,10 +3210,10 @@ error:
|
|||||||
// note changed text for displaying and folding
|
// note changed text for displaying and folding
|
||||||
if (y_type == kMTCharWise) {
|
if (y_type == kMTCharWise) {
|
||||||
changed_lines(curwin->w_cursor.lnum, col,
|
changed_lines(curwin->w_cursor.lnum, col,
|
||||||
curwin->w_cursor.lnum + 1, nr_lines);
|
curwin->w_cursor.lnum + 1, nr_lines, true);
|
||||||
} else {
|
} else {
|
||||||
changed_lines(curbuf->b_op_start.lnum, 0,
|
changed_lines(curbuf->b_op_start.lnum, 0,
|
||||||
curbuf->b_op_start.lnum, nr_lines);
|
curbuf->b_op_start.lnum, nr_lines, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put '] mark at last inserted character */
|
/* put '] mark at last inserted character */
|
||||||
@ -3693,7 +3693,7 @@ int do_join(size_t count,
|
|||||||
/* Only report the change in the first line here, del_lines() will report
|
/* Only report the change in the first line here, del_lines() will report
|
||||||
* the deleted line. */
|
* the deleted line. */
|
||||||
changed_lines(curwin->w_cursor.lnum, currsize,
|
changed_lines(curwin->w_cursor.lnum, currsize,
|
||||||
curwin->w_cursor.lnum + 1, 0L);
|
curwin->w_cursor.lnum + 1, 0L, true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete following lines. To do this we move the cursor there
|
* Delete following lines. To do this we move the cursor there
|
||||||
@ -4363,7 +4363,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
|||||||
}
|
}
|
||||||
change_cnt = do_addsub(oap->op_type, &pos, 0, amount);
|
change_cnt = do_addsub(oap->op_type, &pos, 0, amount);
|
||||||
if (change_cnt) {
|
if (change_cnt) {
|
||||||
changed_lines(pos.lnum, 0, pos.lnum + 1, 0L);
|
changed_lines(pos.lnum, 0, pos.lnum + 1, 0L, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int one_change;
|
int one_change;
|
||||||
@ -4419,7 +4419,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (change_cnt) {
|
if (change_cnt) {
|
||||||
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!change_cnt && oap->is_VIsual) {
|
if (!change_cnt && oap->is_VIsual) {
|
||||||
|
@ -1234,7 +1234,8 @@ static void refresh_screen(Terminal *term, buf_T *buf)
|
|||||||
|
|
||||||
int change_start = row_to_linenr(term, term->invalid_start);
|
int change_start = row_to_linenr(term, term->invalid_start);
|
||||||
int change_end = change_start + changed;
|
int change_end = change_start + changed;
|
||||||
changed_lines(change_start, 0, change_end, added);
|
// Note: don't send LiveUpdate event for a :terminal buffer
|
||||||
|
changed_lines(change_start, 0, change_end, added, false);
|
||||||
term->invalid_start = INT_MAX;
|
term->invalid_start = INT_MAX;
|
||||||
term->invalid_end = -1;
|
term->invalid_end = -1;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@
|
|||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
|
#include "nvim/liveupdate.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
@ -1672,7 +1673,7 @@ void u_undo(int count)
|
|||||||
undo_undoes = TRUE;
|
undo_undoes = TRUE;
|
||||||
else
|
else
|
||||||
undo_undoes = !undo_undoes;
|
undo_undoes = !undo_undoes;
|
||||||
u_doit(count, false);
|
u_doit(count, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1685,7 +1686,7 @@ void u_redo(int count)
|
|||||||
undo_undoes = false;
|
undo_undoes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_doit(count, false);
|
u_doit(count, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Undo and remove the branch from the undo tree.
|
/// Undo and remove the branch from the undo tree.
|
||||||
@ -1697,7 +1698,9 @@ bool u_undo_and_forget(int count)
|
|||||||
count = 1;
|
count = 1;
|
||||||
}
|
}
|
||||||
undo_undoes = true;
|
undo_undoes = true;
|
||||||
u_doit(count, true);
|
// don't send a LiveUpdate for this undo is part of 'inccommand' playing with
|
||||||
|
// buffer contents
|
||||||
|
u_doit(count, true, false);
|
||||||
|
|
||||||
if (curbuf->b_u_curhead == NULL) {
|
if (curbuf->b_u_curhead == NULL) {
|
||||||
// nothing was undone.
|
// nothing was undone.
|
||||||
@ -1732,7 +1735,7 @@ bool u_undo_and_forget(int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Undo or redo, depending on `undo_undoes`, `count` times.
|
/// Undo or redo, depending on `undo_undoes`, `count` times.
|
||||||
static void u_doit(int startcount, bool quiet)
|
static void u_doit(int startcount, bool quiet, bool send_liveupdate)
|
||||||
{
|
{
|
||||||
int count = startcount;
|
int count = startcount;
|
||||||
|
|
||||||
@ -1768,7 +1771,7 @@ static void u_doit(int startcount, bool quiet)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_undoredo(true);
|
u_undoredo(true, send_liveupdate);
|
||||||
} else {
|
} else {
|
||||||
if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) {
|
if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) {
|
||||||
beep_flush(); /* nothing to redo */
|
beep_flush(); /* nothing to redo */
|
||||||
@ -1779,7 +1782,7 @@ static void u_doit(int startcount, bool quiet)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_undoredo(FALSE);
|
u_undoredo(false, send_liveupdate);
|
||||||
|
|
||||||
/* Advance for next redo. Set "newhead" when at the end of the
|
/* Advance for next redo. Set "newhead" when at the end of the
|
||||||
* redoable changes. */
|
* redoable changes. */
|
||||||
@ -2026,7 +2029,7 @@ void undo_time(long step, int sec, int file, int absolute)
|
|||||||
|| (uhp->uh_seq == target && !above))
|
|| (uhp->uh_seq == target && !above))
|
||||||
break;
|
break;
|
||||||
curbuf->b_u_curhead = uhp;
|
curbuf->b_u_curhead = uhp;
|
||||||
u_undoredo(TRUE);
|
u_undoredo(true, true);
|
||||||
uhp->uh_walk = nomark; /* don't go back down here */
|
uhp->uh_walk = nomark; /* don't go back down here */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2082,7 +2085,7 @@ void undo_time(long step, int sec, int file, int absolute)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_undoredo(FALSE);
|
u_undoredo(false, true);
|
||||||
|
|
||||||
/* Advance "curhead" to below the header we last used. If it
|
/* Advance "curhead" to below the header we last used. If it
|
||||||
* becomes NULL then we need to set "newhead" to this leaf. */
|
* becomes NULL then we need to set "newhead" to this leaf. */
|
||||||
@ -2114,7 +2117,7 @@ void undo_time(long step, int sec, int file, int absolute)
|
|||||||
*
|
*
|
||||||
* When "undo" is TRUE we go up in the tree, when FALSE we go down.
|
* When "undo" is TRUE we go up in the tree, when FALSE we go down.
|
||||||
*/
|
*/
|
||||||
static void u_undoredo(int undo)
|
static void u_undoredo(int undo, bool send_liveupdate)
|
||||||
{
|
{
|
||||||
char_u **newarray = NULL;
|
char_u **newarray = NULL;
|
||||||
linenr_T oldsize;
|
linenr_T oldsize;
|
||||||
@ -2242,7 +2245,7 @@ static void u_undoredo(int undo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines(top + 1, 0, bot, newsize - oldsize);
|
changed_lines(top + 1, 0, bot, newsize - oldsize, send_liveupdate);
|
||||||
|
|
||||||
/* set '[ and '] mark */
|
/* set '[ and '] mark */
|
||||||
if (top + 1 < curbuf->b_op_start.lnum)
|
if (top + 1 < curbuf->b_op_start.lnum)
|
||||||
@ -2277,6 +2280,13 @@ static void u_undoredo(int undo)
|
|||||||
unchanged(curbuf, FALSE);
|
unchanged(curbuf, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// because the calls to changed()/unchanged() above will bump b_changedtick
|
||||||
|
// again, we need to send a LiveUpdate with just the new value of
|
||||||
|
// b:changedtick
|
||||||
|
if (send_liveupdate && kv_size(curbuf->liveupdate_channels)) {
|
||||||
|
liveupdate_send_tick(curbuf);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* restore marks from before undo/redo
|
* restore marks from before undo/redo
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user