aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/vim.c9
-rw-r--r--src/nvim/getchar.c10
-rw-r--r--test/functional/api/vim_spec.lua7
3 files changed, 15 insertions, 11 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index ae649e55d6..d18cfaccd0 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1248,7 +1248,8 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
/// @return
/// - true: Client may continue pasting.
/// - false: Client should cancel the paste.
-Boolean nvim_paste(String data, Boolean crlf, Integer phase, Arena *arena, Error *err)
+Boolean nvim_paste(uint64_t channel_id, String data, Boolean crlf, Integer phase, Arena *arena,
+ Error *err)
FUNC_API_SINCE(6)
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
{
@@ -1273,13 +1274,13 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Arena *arena, Error
cancelled = true;
}
if (!cancelled && (phase == -1 || phase == 1)) {
- paste_store(kFalse, NULL_STRING, crlf);
+ paste_store(channel_id, kFalse, NULL_STRING, crlf);
}
if (!cancelled) {
- paste_store(kNone, data, crlf);
+ paste_store(channel_id, kNone, data, crlf);
}
if (phase == 3 || phase == (cancelled ? 2 : -1)) {
- paste_store(kTrue, NULL_STRING, crlf);
+ paste_store(channel_id, kTrue, NULL_STRING, crlf);
}
theend:
;
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 31f31904e0..8c3ac49adf 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -3190,8 +3190,6 @@ bool map_execute_lua(bool may_repeat)
return true;
}
-static bool paste_repeat_active = false; ///< true when paste_repeat() is pasting
-
/// Wraps pasted text stream with K_PASTE_START and K_PASTE_END, and
/// appends to redo buffer and/or record buffer if needed.
/// Escapes all K_SPECIAL and NUL bytes in the content.
@@ -3200,14 +3198,14 @@ static bool paste_repeat_active = false; ///< true when paste_repeat() is pasti
/// kTrue for the end of a paste
/// kNone for the content of a paste
/// @param str the content of the paste (only used when state is kNone)
-void paste_store(const TriState state, const String str, const bool crlf)
+void paste_store(const uint64_t channel_id, const TriState state, const String str, const bool crlf)
{
if (State & MODE_CMDLINE) {
return;
}
const bool need_redo = !block_redo;
- const bool need_record = reg_recording != 0 && !paste_repeat_active;
+ const bool need_record = reg_recording != 0 && !is_internal_call(channel_id);
if (!need_redo && !need_record) {
return;
@@ -3302,12 +3300,10 @@ void paste_repeat(int count)
String str = cbuf_as_string(ga.ga_data, (size_t)ga.ga_len);
Arena arena = ARENA_EMPTY;
Error err = ERROR_INIT;
- paste_repeat_active = true;
for (int i = 0; !aborted && i < count; i++) {
- nvim_paste(str, false, -1, &arena, &err);
+ nvim_paste(LUA_INTERNAL_CALL, str, false, -1, &arena, &err);
aborted = ERROR_SET(&err);
}
- paste_repeat_active = false;
api_clear_error(&err);
arena_mem_free(arena_finish(&arena));
ga_clear(&ga);
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 1b34945f13..af4d4854f5 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1358,6 +1358,13 @@ describe('API', function()
test_paste_repeat_visual_select(true)
end)
end)
+ it('in a mapping recorded in a macro', function()
+ command([[nnoremap <F2> <Cmd>call nvim_paste('foo', v:false, -1)<CR>]])
+ feed('qr<F2>$q')
+ expect('foo')
+ feed('@r') -- repeating a macro containing the mapping should only paste once
+ expect('foofoo')
+ end)
local function test_paste_cancel_error(is_error)
before_each(function()
exec_lua(([[