mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #13539 from vigoux/ts-fix-icmnosplit
fix: also splice extmarks in preview buffers
This commit is contained in:
commit
958ebc7337
@ -50,7 +50,7 @@ function M._create_parser(bufnr, lang, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
a.nvim_buf_attach(self.bufnr, false, {on_bytes=bytes_cb, on_detach=detach_cb})
|
a.nvim_buf_attach(self.bufnr, false, {on_bytes=bytes_cb, on_detach=detach_cb, preview=true})
|
||||||
|
|
||||||
self:parse()
|
self:parse()
|
||||||
|
|
||||||
|
@ -121,6 +121,8 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
|
|||||||
/// - buffer handle
|
/// - buffer handle
|
||||||
/// - utf_sizes: include UTF-32 and UTF-16 size of the replaced
|
/// - utf_sizes: include UTF-32 and UTF-16 size of the replaced
|
||||||
/// region, as args to `on_lines`.
|
/// region, as args to `on_lines`.
|
||||||
|
/// - preview: also attach to command preview (i.e. 'inccommand')
|
||||||
|
/// events.
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
/// @return False if attach failed (invalid parameter, or buffer isn't loaded);
|
/// @return False if attach failed (invalid parameter, or buffer isn't loaded);
|
||||||
/// otherwise True. TODO: LUA_API_NO_EVAL
|
/// otherwise True. TODO: LUA_API_NO_EVAL
|
||||||
@ -176,6 +178,12 @@ Boolean nvim_buf_attach(uint64_t channel_id,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
cb.utf_sizes = v->data.boolean;
|
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 {
|
} else {
|
||||||
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -491,9 +491,10 @@ typedef struct {
|
|||||||
LuaRef on_changedtick;
|
LuaRef on_changedtick;
|
||||||
LuaRef on_detach;
|
LuaRef on_detach;
|
||||||
bool utf_sizes;
|
bool utf_sizes;
|
||||||
|
bool preview;
|
||||||
} BufUpdateCallbacks;
|
} BufUpdateCallbacks;
|
||||||
#define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, \
|
#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);
|
EXTERN int curbuf_splice_pending INIT(= 0);
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ void buf_updates_send_changes(buf_T *buf,
|
|||||||
for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
|
for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
|
||||||
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
|
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
|
||||||
bool keep = true;
|
bool keep = true;
|
||||||
if (cb.on_lines != LUA_NOREF) {
|
if (cb.on_lines != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
Object items[8];
|
Object items[8];
|
||||||
args.size = 6; // may be increased to 8 below
|
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++) {
|
for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
|
||||||
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
|
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
|
||||||
bool keep = true;
|
bool keep = true;
|
||||||
if (cb.on_bytes != LUA_NOREF) {
|
if (cb.on_bytes != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) {
|
||||||
FIXED_TEMP_ARRAY(args, 11);
|
FIXED_TEMP_ARRAY(args, 11);
|
||||||
|
|
||||||
// the first argument is always the buffer handle
|
// the first argument is always the buffer handle
|
||||||
|
@ -3909,17 +3909,13 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
|
|
||||||
ADJUST_SUB_FIRSTLNUM();
|
ADJUST_SUB_FIRSTLNUM();
|
||||||
|
|
||||||
// TODO(bfredl): adjust also in preview, because decorations?
|
// TODO(bfredl): this has some robustness issues, look into later.
|
||||||
// this has some robustness issues, will look into later.
|
|
||||||
bool do_splice = !preview;
|
|
||||||
bcount_t replaced_bytes = 0;
|
bcount_t replaced_bytes = 0;
|
||||||
lpos_T start = regmatch.startpos[0], end = regmatch.endpos[0];
|
lpos_T start = regmatch.startpos[0], end = regmatch.endpos[0];
|
||||||
if (do_splice) {
|
|
||||||
for (i = 0; i < nmatch-1; i++) {
|
for (i = 0; i < nmatch-1; i++) {
|
||||||
replaced_bytes += STRLEN(ml_get(lnum_start+i)) + 1;
|
replaced_bytes += STRLEN(ml_get(lnum_start+i)) + 1;
|
||||||
}
|
}
|
||||||
replaced_bytes += end.col - start.col;
|
replaced_bytes += end.col - start.col;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Now the trick is to replace CTRL-M chars with a real line
|
// Now the trick is to replace CTRL-M chars with a real line
|
||||||
@ -3964,7 +3960,6 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
current_match.end.col = new_endcol;
|
current_match.end.col = new_endcol;
|
||||||
current_match.end.lnum = lnum;
|
current_match.end.lnum = lnum;
|
||||||
|
|
||||||
if (do_splice) {
|
|
||||||
int matchcols = end.col - ((end.lnum == start.lnum)
|
int matchcols = end.col - ((end.lnum == start.lnum)
|
||||||
? start.col : 0);
|
? start.col : 0);
|
||||||
int subcols = new_endcol - ((lnum == lnum_start) ? start_col : 0);
|
int subcols = new_endcol - ((lnum == lnum_start) ? start_col : 0);
|
||||||
@ -3972,7 +3967,6 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
|
|||||||
end.lnum-start.lnum, matchcols, replaced_bytes,
|
end.lnum-start.lnum, matchcols, replaced_bytes,
|
||||||
lnum-lnum_start, subcols, sublen-1, kExtmarkUndo);
|
lnum-lnum_start, subcols, sublen-1, kExtmarkUndo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 4. If subflags.do_all is set, find next match.
|
// 4. If subflags.do_all is set, find next match.
|
||||||
|
@ -25,14 +25,14 @@ local function attach_buffer(evname)
|
|||||||
local evname = ...
|
local evname = ...
|
||||||
local events = {}
|
local events = {}
|
||||||
|
|
||||||
function test_register(bufnr, id, changedtick, utf_sizes)
|
function test_register(bufnr, id, changedtick, utf_sizes, preview)
|
||||||
local function callback(...)
|
local function callback(...)
|
||||||
table.insert(events, {id, ...})
|
table.insert(events, {id, ...})
|
||||||
if test_unreg == id then
|
if test_unreg == id then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes}
|
local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes, preview=preview}
|
||||||
if changedtick then
|
if changedtick then
|
||||||
opts.on_changedtick = callback
|
opts.on_changedtick = callback
|
||||||
end
|
end
|
||||||
@ -290,7 +290,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
|||||||
if verify then
|
if verify then
|
||||||
meths.buf_get_offset(0, meths.buf_line_count(0))
|
meths.buf_get_offset(0, meths.buf_line_count(0))
|
||||||
end
|
end
|
||||||
exec_lua("return test_register(...)", 0, "test1",false, nil)
|
exec_lua("return test_register(...)", 0, "test1", false, false, true)
|
||||||
meths.buf_get_changedtick(0)
|
meths.buf_get_changedtick(0)
|
||||||
|
|
||||||
local verify_name = "test1"
|
local verify_name = "test1"
|
||||||
@ -493,6 +493,23 @@ describe('lua: nvim_buf_attach on_bytes', function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('inccomand=nosplit and substitute', function()
|
||||||
|
if verify then pending("Verification can't be done when previewing") end
|
||||||
|
|
||||||
|
local check_events = setup_eventcheck(verify, {"abcde"})
|
||||||
|
meths.set_option('inccommand', 'nosplit')
|
||||||
|
|
||||||
|
feed ':%s/bcd/'
|
||||||
|
check_events {
|
||||||
|
{ "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
feed 'a'
|
||||||
|
check_events {
|
||||||
|
{ "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 };
|
||||||
|
}
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe('(with verify) handles', function()
|
describe('(with verify) handles', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user