diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-12-16 12:05:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 12:05:01 +0100 |
commit | 958ebc7337bb9ee8d39516f0a079cd518a3e3ef4 (patch) | |
tree | 2d8e74a857580adcee0bf1d9450d3fd6fd2daa37 /src | |
parent | c3b9c35876bf82b5bd53543bc7222ef3599eb057 (diff) | |
parent | 25e20da550b0d267013ac295756bad76f5fda7ef (diff) | |
download | rneovim-958ebc7337bb9ee8d39516f0a079cd518a3e3ef4.tar.gz rneovim-958ebc7337bb9ee8d39516f0a079cd518a3e3ef4.tar.bz2 rneovim-958ebc7337bb9ee8d39516f0a079cd518a3e3ef4.zip |
Merge pull request #13539 from vigoux/ts-fix-icmnosplit
fix: also splice extmarks in preview buffers
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/buffer.c | 8 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 3 | ||||
-rw-r--r-- | src/nvim/buffer_updates.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 26 |
4 files changed, 22 insertions, 19 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index db37e2100d..45545d24d9 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -121,6 +121,8 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) /// - buffer handle /// - utf_sizes: include UTF-32 and UTF-16 size of the replaced /// region, as args to `on_lines`. +/// - preview: also attach to command preview (i.e. 'inccommand') +/// events. /// @param[out] err Error details, if any /// @return False if attach failed (invalid parameter, or buffer isn't loaded); /// otherwise True. TODO: LUA_API_NO_EVAL @@ -176,6 +178,12 @@ Boolean nvim_buf_attach(uint64_t channel_id, goto error; } cb.utf_sizes = v->data.boolean; + } else if (is_lua && strequal("preview", k.data)) { + if (v->type != kObjectTypeBoolean) { + api_set_error(err, kErrorTypeValidation, "preview must be boolean"); + goto error; + } + cb.preview = v->data.boolean; } else { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); goto error; diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index dba02a67e8..44a9b39939 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -491,9 +491,10 @@ typedef struct { LuaRef on_changedtick; LuaRef on_detach; bool utf_sizes; + bool preview; } BufUpdateCallbacks; #define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, \ - LUA_NOREF, false } + LUA_NOREF, false, false } EXTERN int curbuf_splice_pending INIT(= 0); diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index fc671ad9e2..68e123896b 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -237,7 +237,7 @@ void buf_updates_send_changes(buf_T *buf, 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_lines != LUA_NOREF) { + if (cb.on_lines != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) { Array args = ARRAY_DICT_INIT; Object items[8]; args.size = 6; // may be increased to 8 below @@ -298,7 +298,7 @@ void buf_updates_send_splice( 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) { + if (cb.on_bytes != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) { FIXED_TEMP_ARRAY(args, 11); // the first argument is always the buffer handle diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b0a51eaefd..39902cf18e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3909,17 +3909,13 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, ADJUST_SUB_FIRSTLNUM(); - // TODO(bfredl): adjust also in preview, because decorations? - // this has some robustness issues, will look into later. - bool do_splice = !preview; + // TODO(bfredl): this has some robustness issues, look into later. bcount_t replaced_bytes = 0; lpos_T start = regmatch.startpos[0], end = regmatch.endpos[0]; - if (do_splice) { - for (i = 0; i < nmatch-1; i++) { - replaced_bytes += STRLEN(ml_get(lnum_start+i)) + 1; - } - replaced_bytes += end.col - start.col; + for (i = 0; i < nmatch-1; i++) { + replaced_bytes += STRLEN(ml_get(lnum_start+i)) + 1; } + replaced_bytes += end.col - start.col; // Now the trick is to replace CTRL-M chars with a real line @@ -3964,14 +3960,12 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, current_match.end.col = new_endcol; current_match.end.lnum = lnum; - if (do_splice) { - int matchcols = end.col - ((end.lnum == start.lnum) - ? start.col : 0); - int subcols = new_endcol - ((lnum == lnum_start) ? start_col : 0); - extmark_splice(curbuf, lnum_start-1, start_col, - end.lnum-start.lnum, matchcols, replaced_bytes, - lnum-lnum_start, subcols, sublen-1, kExtmarkUndo); - } + int matchcols = end.col - ((end.lnum == start.lnum) + ? start.col : 0); + int subcols = new_endcol - ((lnum == lnum_start) ? start_col : 0); + extmark_splice(curbuf, lnum_start-1, start_col, + end.lnum-start.lnum, matchcols, replaced_bytes, + lnum-lnum_start, subcols, sublen-1, kExtmarkUndo); } |