mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 18:28:19 +00:00
paste: edge-case: handle EOL at end-of-buffer
This is "readfile()-style", see also ":help channel-lines".
This commit is contained in:
@@ -4214,17 +4214,6 @@ getchar([expr]) *getchar()*
|
|||||||
: endwhile
|
: endwhile
|
||||||
:endfunction
|
:endfunction
|
||||||
<
|
<
|
||||||
You may also receive synthetic characters, such as
|
|
||||||
|<LeftMouse>|. Often you will want to ignore this and get
|
|
||||||
another character: >
|
|
||||||
:function GetKey()
|
|
||||||
: let c = getchar()
|
|
||||||
: while c == "\<LeftMouse>"
|
|
||||||
: let c = getchar()
|
|
||||||
: endwhile
|
|
||||||
: return c
|
|
||||||
:endfunction
|
|
||||||
|
|
||||||
getcharmod() *getcharmod()*
|
getcharmod() *getcharmod()*
|
||||||
The result is a Number which is the state of the modifiers for
|
The result is a Number which is the state of the modifiers for
|
||||||
the last obtained character with getchar() or in another way.
|
the last obtained character with getchar() or in another way.
|
||||||
|
@@ -1210,9 +1210,13 @@ Dictionary nvim_get_namespaces(void)
|
|||||||
///
|
///
|
||||||
/// Compare |:put| and |p| which are always linewise.
|
/// Compare |:put| and |p| which are always linewise.
|
||||||
///
|
///
|
||||||
/// @param lines contents
|
/// @param lines |readfile()|-style list of lines. |channel-lines|
|
||||||
/// @param type type ("c", "l", "b") or empty to guess from contents
|
/// @param type Edit behavior:
|
||||||
/// @param direction behave like |P| instead of |p|
|
/// - "b" |blockwise-visual| mode
|
||||||
|
/// - "c" |characterwise| mode
|
||||||
|
/// - "l" |linewise| mode
|
||||||
|
/// - "" guess by contents
|
||||||
|
/// @param direction Behave like |P| instead of |p|
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
void nvim_put(ArrayOf(String) lines, String type, Boolean direction,
|
void nvim_put(ArrayOf(String) lines, String type, Boolean direction,
|
||||||
Error *err)
|
Error *err)
|
||||||
|
@@ -104,9 +104,9 @@ static Array string_to_array(const String input)
|
|||||||
{
|
{
|
||||||
Array ret = ARRAY_DICT_INIT;
|
Array ret = ARRAY_DICT_INIT;
|
||||||
for (size_t i = 0; i < input.size; i++) {
|
for (size_t i = 0; i < input.size; i++) {
|
||||||
const char *const start = input.data + i;
|
const char *start = input.data + i;
|
||||||
const size_t line_len
|
const char *end = xmemscan(start, NL, input.size - i);
|
||||||
= (size_t)((char *)xmemscan(start, NL, input.size - i) - start);
|
const size_t line_len = (size_t)(end - start);
|
||||||
i += line_len;
|
i += line_len;
|
||||||
|
|
||||||
String s = {
|
String s = {
|
||||||
@@ -115,6 +115,11 @@ static Array string_to_array(const String input)
|
|||||||
};
|
};
|
||||||
memchrsub(s.data, NUL, NL, line_len);
|
memchrsub(s.data, NUL, NL, line_len);
|
||||||
ADD(ret, STRING_OBJ(s));
|
ADD(ret, STRING_OBJ(s));
|
||||||
|
// If line ends at end-of-buffer, add empty final item.
|
||||||
|
// This is "readfile()-style", see also ":help channel-lines".
|
||||||
|
if (i + 1 == input.size && end[0] == NL) {
|
||||||
|
ADD(ret, STRING_OBJ(cchar_to_string(NUL)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -189,20 +189,20 @@ describe('TUI', function()
|
|||||||
it('paste: exactly 64 bytes #10311', function()
|
it('paste: exactly 64 bytes #10311', function()
|
||||||
-- "bracketed paste"
|
-- "bracketed paste"
|
||||||
feed_data('i\027[200~'..string.rep('z', 64)..'\027[201~')
|
feed_data('i\027[200~'..string.rep('z', 64)..'\027[201~')
|
||||||
feed_data('\003') -- CTRL-C
|
feed_data(' end')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz|
|
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz|
|
||||||
zzzzzzzzzzzzz{1:z} |
|
zzzzzzzzzzzzzz end{1: } |
|
||||||
{4:~ }|
|
{4:~ }|
|
||||||
{4:~ }|
|
{4:~ }|
|
||||||
{5:[No Name] [+] }|
|
{5:[No Name] [+] }|
|
||||||
|
|
{3:-- INSERT --} |
|
||||||
{3:-- TERMINAL --} |
|
{3:-- TERMINAL --} |
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('paste: big burst of input', function()
|
it('paste: big burst of input', function()
|
||||||
feed_command('set ruler')
|
feed_data(':set ruler\013')
|
||||||
local t = {}
|
local t = {}
|
||||||
for i = 1, 3000 do
|
for i = 1, 3000 do
|
||||||
t[i] = 'item ' .. tostring(i)
|
t[i] = 'item ' .. tostring(i)
|
||||||
@@ -210,12 +210,13 @@ describe('TUI', function()
|
|||||||
local expected = table.concat(t, '\n')
|
local expected = table.concat(t, '\n')
|
||||||
-- "bracketed paste"
|
-- "bracketed paste"
|
||||||
feed_data('i\027[200~'..expected..'\027[201~')
|
feed_data('i\027[200~'..expected..'\027[201~')
|
||||||
|
feed_data(' end')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
item 2997 |
|
item 2997 |
|
||||||
item 2998 |
|
item 2998 |
|
||||||
item 2999 |
|
item 2999 |
|
||||||
item 3000{1: } |
|
item 3000 end{1: } |
|
||||||
{5:[No Name] [+] 3000,10 Bot}|
|
{5:[No Name] [+] 3000,14 Bot}|
|
||||||
{3:-- INSERT --} |
|
{3:-- INSERT --} |
|
||||||
{3:-- TERMINAL --} |
|
{3:-- TERMINAL --} |
|
||||||
]])
|
]])
|
||||||
|
Reference in New Issue
Block a user