aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index d51b4cc88b..2491621fbc 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -5236,18 +5236,37 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str,
// Find the end of each line and save it into the array.
if (str_list) {
for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) {
- size_t ss_len = strlen(*ss);
- pp[lnum] = cbuf_to_string(*ss, ss_len);
- maxlen = MAX(maxlen, ss_len);
+ pp[lnum] = cstr_to_string(*ss);
+ if (yank_type == kMTBlockWise) {
+ size_t charlen = mb_string2cells(*ss);
+ maxlen = MAX(maxlen, charlen);
+ }
}
} else {
size_t line_len;
for (const char *start = str, *end = str + len;
start < end + extraline;
start += line_len + 1, lnum++) {
- assert(end - start >= 0);
- line_len = (size_t)((char *)xmemscan(start, '\n', (size_t)(end - start)) - start);
- maxlen = MAX(maxlen, line_len);
+ int charlen = 0;
+
+ const char *line_end = start;
+ while (line_end < end) { // find the end of the line
+ if (*line_end == '\n') {
+ break;
+ }
+ if (yank_type == kMTBlockWise) {
+ charlen += utf_ptr2cells_len(line_end, (int)(end - line_end));
+ }
+
+ if (*line_end == NUL) {
+ line_end++; // registers can have NUL chars
+ } else {
+ line_end += utf_ptr2len_len(line_end, (int)(end - line_end));
+ }
+ }
+ assert(line_end - start >= 0);
+ line_len = (size_t)(line_end - start);
+ maxlen = MAX(maxlen, (size_t)charlen);
// When appending, copy the previous line and free it after.
size_t extra = append ? pp[--lnum].size : 0;
@@ -5255,7 +5274,9 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str,
if (extra > 0) {
memcpy(s, pp[lnum].data, extra);
}
- memcpy(s + extra, start, line_len);
+ if (line_len > 0) {
+ memcpy(s + extra, start, line_len);
+ }
size_t s_len = extra + line_len;
if (append) {