mirror of
https://github.com/neovim/neovim.git
synced 2025-10-18 07:41:51 +00:00
Merge PR #1270 'Add Boolean argument escape_csi to vim_feedkeys'
This commit is contained in:
@@ -49,8 +49,10 @@ void vim_command(String str, Error *err)
|
|||||||
///
|
///
|
||||||
/// @param keys to be typed
|
/// @param keys to be typed
|
||||||
/// @param mode specifies the mapping options
|
/// @param mode specifies the mapping options
|
||||||
|
/// @param escape_csi the string needs escaping for K_SPECIAL/CSI bytes
|
||||||
/// @see feedkeys()
|
/// @see feedkeys()
|
||||||
void vim_feedkeys(String keys, String mode)
|
/// @see vim_strsave_escape_csi
|
||||||
|
void vim_feedkeys(String keys, String mode, Boolean escape_csi)
|
||||||
FUNC_ATTR_DEFERRED
|
FUNC_ATTR_DEFERRED
|
||||||
{
|
{
|
||||||
bool remap = true;
|
bool remap = true;
|
||||||
@@ -68,12 +70,20 @@ void vim_feedkeys(String keys, String mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Need to escape K_SPECIAL and CSI before putting the string in the
|
char *keys_esc;
|
||||||
* typeahead buffer. */
|
if (escape_csi) {
|
||||||
char *keys_esc = (char *)vim_strsave_escape_csi((char_u *)keys.data);
|
// Need to escape K_SPECIAL and CSI before putting the string in the
|
||||||
|
// typeahead buffer.
|
||||||
|
keys_esc = (char *)vim_strsave_escape_csi((char_u *)keys.data);
|
||||||
|
} else {
|
||||||
|
keys_esc = keys.data;
|
||||||
|
}
|
||||||
ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE),
|
ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE),
|
||||||
typebuf.tb_len, !typed, false);
|
typebuf.tb_len, !typed, false);
|
||||||
|
|
||||||
|
if (escape_csi) {
|
||||||
free(keys_esc);
|
free(keys_esc);
|
||||||
|
}
|
||||||
|
|
||||||
if (vgetc_busy)
|
if (vgetc_busy)
|
||||||
typebuf_was_filled = true;
|
typebuf_was_filled = true;
|
||||||
|
@@ -8414,7 +8414,7 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim_feedkeys(cstr_as_string((char *)keys),
|
vim_feedkeys(cstr_as_string((char *)keys),
|
||||||
cstr_as_string((char *)flags));
|
cstr_as_string((char *)flags), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
-- Sanity checks for vim_* API calls via msgpack-rpc
|
-- Sanity checks for vim_* API calls via msgpack-rpc
|
||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local clear, nvim, eq, ok = helpers.clear, helpers.nvim, helpers.eq, helpers.ok
|
local clear, nvim, eq, neq, ok = helpers.clear, helpers.nvim, helpers.eq, helpers.neq, helpers.ok
|
||||||
|
|
||||||
|
|
||||||
describe('vim_* functions', function()
|
describe('vim_* functions', function()
|
||||||
@@ -106,6 +106,47 @@ describe('vim_* functions', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('replace_termcodes', function()
|
||||||
|
it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function()
|
||||||
|
eq(helpers.nvim('replace_termcodes', '\x80', true, true, true), '\x80\xfeX')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('leaves non K_SPECIAL string unchanged', function()
|
||||||
|
eq(helpers.nvim('replace_termcodes', 'abc', true, true, true), 'abc')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('converts <expressions>', function()
|
||||||
|
eq(helpers.nvim('replace_termcodes', '<Leader>', true, true, true), '\\')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('feedkeys', function()
|
||||||
|
it('CSI escaping', function()
|
||||||
|
local function on_setup()
|
||||||
|
-- notice the special char(…) \xe2\80\xa6
|
||||||
|
nvim('feedkeys', ':let x1="…"\n', '', true)
|
||||||
|
|
||||||
|
-- Both replace_termcodes and feedkeys escape \x80
|
||||||
|
local inp = helpers.nvim('replace_termcodes', ':let x2="…"<CR>', true, true, true)
|
||||||
|
nvim('feedkeys', inp, '', true)
|
||||||
|
|
||||||
|
-- Disabling CSI escaping in feedkeys
|
||||||
|
inp = helpers.nvim('replace_termcodes', ':let x3="…"<CR>', true, true, true)
|
||||||
|
nvim('feedkeys', inp, '', false)
|
||||||
|
|
||||||
|
helpers.stop()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- spin the loop a bit
|
||||||
|
helpers.run(nil, nil, on_setup)
|
||||||
|
|
||||||
|
eq(nvim('get_var', 'x1'), '…')
|
||||||
|
-- Because of the double escaping this is neq
|
||||||
|
neq(nvim('get_var', 'x2'), '…')
|
||||||
|
eq(nvim('get_var', 'x3'), '…')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
it('can throw exceptions', function()
|
it('can throw exceptions', function()
|
||||||
local status, err = pcall(nvim, 'get_option', 'invalid-option')
|
local status, err = pcall(nvim, 'get_option', 'invalid-option')
|
||||||
eq(false, status)
|
eq(false, status)
|
||||||
|
Reference in New Issue
Block a user