diff options
Diffstat (limited to 'src/nvim/buffer_updates.c')
-rw-r--r-- | src/nvim/buffer_updates.c | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index 3604578b50..e6393bf02c 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -157,7 +157,7 @@ void buf_updates_unregister_all(buf_T *buf) args.items[0] = BUFFER_OBJ(buf->handle); textlock++; - executor_exec_lua_cb(cb.on_detach, "detach", args, false); + executor_exec_lua_cb(cb.on_detach, "detach", args, false, NULL); textlock--; } free_update_callbacks(cb); @@ -265,7 +265,7 @@ void buf_updates_send_changes(buf_T *buf, args.items[7] = INTEGER_OBJ((Integer)deleted_codeunits); } textlock++; - Object res = executor_exec_lua_cb(cb.on_lines, "lines", args, true); + Object res = executor_exec_lua_cb(cb.on_lines, "lines", args, true, NULL); textlock--; if (res.type == kObjectTypeBoolean && res.data.boolean == true) { @@ -281,6 +281,51 @@ void buf_updates_send_changes(buf_T *buf, kv_size(buf->update_callbacks) = j; } +void buf_updates_send_splice(buf_T *buf, + linenr_T start_line, colnr_T start_col, + linenr_T oldextent_line, colnr_T oldextent_col, + linenr_T newextent_line, colnr_T newextent_col) +{ + if (!buf_updates_active(buf)) { + return; + } + + // notify each of the active callbakcs + size_t j = 0; + for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) { + BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i); + bool keep = true; + if (cb.on_bytes != LUA_NOREF) { + FIXED_TEMP_ARRAY(args, 8); + + // 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_get_changedtick(buf)); + + args.items[2] = INTEGER_OBJ(start_line); + args.items[3] = INTEGER_OBJ(start_col); + args.items[4] = INTEGER_OBJ(oldextent_line); + args.items[5] = INTEGER_OBJ(oldextent_col); + args.items[6] = INTEGER_OBJ(newextent_line); + args.items[7] = INTEGER_OBJ(newextent_col); + + textlock++; + Object res = executor_exec_lua_cb(cb.on_bytes, "bytes", args, true, NULL); + textlock--; + + if (res.type == kObjectTypeBoolean && res.data.boolean == true) { + free_update_callbacks(cb); + keep = false; + } + } + if (keep) { + kv_A(buf->update_callbacks, j++) = kv_A(buf->update_callbacks, i); + } + } + kv_size(buf->update_callbacks) = j; +} void buf_updates_changedtick(buf_T *buf) { // notify each of the active channels @@ -293,10 +338,7 @@ void buf_updates_changedtick(buf_T *buf) BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i); bool keep = true; if (cb.on_changedtick != LUA_NOREF) { - Array args = ARRAY_DICT_INIT; - Object items[2]; - args.size = 2; - args.items = items; + FIXED_TEMP_ARRAY(args, 2); // the first argument is always the buffer handle args.items[0] = BUFFER_OBJ(buf->handle); @@ -306,7 +348,7 @@ void buf_updates_changedtick(buf_T *buf) textlock++; Object res = executor_exec_lua_cb(cb.on_changedtick, "changedtick", - args, true); + args, true, NULL); textlock--; if (res.type == kObjectTypeBoolean && res.data.boolean == true) { |