mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +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:
@@ -1210,9 +1210,13 @@ Dictionary nvim_get_namespaces(void)
|
||||
///
|
||||
/// Compare |:put| and |p| which are always linewise.
|
||||
///
|
||||
/// @param lines contents
|
||||
/// @param type type ("c", "l", "b") or empty to guess from contents
|
||||
/// @param direction behave like |P| instead of |p|
|
||||
/// @param lines |readfile()|-style list of lines. |channel-lines|
|
||||
/// @param type Edit behavior:
|
||||
/// - "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
|
||||
void nvim_put(ArrayOf(String) lines, String type, Boolean direction,
|
||||
Error *err)
|
||||
|
@@ -104,9 +104,9 @@ static Array string_to_array(const String input)
|
||||
{
|
||||
Array ret = ARRAY_DICT_INIT;
|
||||
for (size_t i = 0; i < input.size; i++) {
|
||||
const char *const start = input.data + i;
|
||||
const size_t line_len
|
||||
= (size_t)((char *)xmemscan(start, NL, input.size - i) - start);
|
||||
const char *start = input.data + i;
|
||||
const char *end = xmemscan(start, NL, input.size - i);
|
||||
const size_t line_len = (size_t)(end - start);
|
||||
i += line_len;
|
||||
|
||||
String s = {
|
||||
@@ -115,6 +115,11 @@ static Array string_to_array(const String input)
|
||||
};
|
||||
memchrsub(s.data, NUL, NL, line_len);
|
||||
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;
|
||||
|
Reference in New Issue
Block a user