aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2015-03-28 20:57:06 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2015-04-05 11:34:13 +0200
commit7422843f5c86b0dc18e26e5a2436f9d8e7013e12 (patch)
treef9550d3dbb463e8bcc8482151d02822a1cb0538d /src/nvim/ops.c
parent34dba3d7cd43b4797d60f636dc9c7c3040a56f3c (diff)
downloadrneovim-7422843f5c86b0dc18e26e5a2436f9d8e7013e12.tar.gz
rneovim-7422843f5c86b0dc18e26e5a2436f9d8e7013e12.tar.bz2
rneovim-7422843f5c86b0dc18e26e5a2436f9d8e7013e12.zip
clipboard: improve the handling of newlines in `get_clipboard`
This makes the interpretion consistent with the way newlines are used in the VIMENC format, while keeping the same fallback behaviour when regtype is unspecified. Also check both cases explicitly in the tests.
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index e73868a0fa..f0caaad97b 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -5360,10 +5360,13 @@ static void get_clipboard(int name, bool quiet)
goto err;
}
char_u* regtype = res->lv_last->li_tv.vval.v_string;
- if (regtype == NULL || strlen((char*)regtype) != 1) {
+ if (regtype == NULL || strlen((char*)regtype) > 1) {
goto err;
}
switch (regtype[0]) {
+ case 0:
+ reg->y_type = MAUTO;
+ break;
case 'v': case 'c':
reg->y_type = MCHAR;
break;
@@ -5393,15 +5396,23 @@ static void get_clipboard(int name, bool quiet)
reg->y_array[i++] = (uint8_t *)xstrdup((char *)li->li_tv.vval.v_string);
}
- if (reg->y_type == MAUTO) {
- if (reg->y_size > 0 && strlen((char*)reg->y_array[reg->y_size-1]) == 0) {
- reg->y_type = MLINE;
+ if (reg->y_size > 0 && strlen((char*)reg->y_array[reg->y_size-1]) == 0) {
+ // a known-to-be charwise yank might have a final linebreak
+ // but otherwise there is no line after the final newline
+ if (reg->y_type != MCHAR) {
free(reg->y_array[reg->y_size-1]);
reg->y_size--;
- } else {
+ if (reg->y_type == MAUTO) {
+ reg->y_type = MLINE;
+ }
+ }
+ } else {
+ if (reg->y_type == MAUTO) {
reg->y_type = MCHAR;
}
- } else if (reg->y_type == MBLOCK) {
+ }
+
+ if (reg->y_type == MBLOCK) {
int maxlen = 0;
for (int i = 0; i < reg->y_size; i++) {
int rowlen = STRLEN(reg->y_array[i]);
@@ -5453,6 +5464,7 @@ static void set_clipboard(int name)
break;
case MBLOCK:
regtype = 'b';
+ list_append_string(lines, (char_u*)"", 0);
break;
}
list_append_string(args, &regtype, 1);