diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-08-28 01:56:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-28 01:56:02 +0200 |
commit | 82d52b229df711b710862ce772603ea55113a32e (patch) | |
tree | c097dd598d961b9090a682cf8267ca615d42b592 /src/nvim/ops.c | |
parent | 3c9c64d9dd486598f36c597da1eaffebb3bf4cef (diff) | |
parent | 3157baed83b7e94f2ff92e6fd97e85dab41a1c94 (diff) | |
download | rneovim-82d52b229df711b710862ce772603ea55113a32e.tar.gz rneovim-82d52b229df711b710862ce772603ea55113a32e.tar.bz2 rneovim-82d52b229df711b710862ce772603ea55113a32e.zip |
Merge #4448 'paste: redesign'
fix #3447
fix #3566
fix #7066
fix #7212
fix #7273
fix #7455
fix #10415
NA vim-patches:
vim-patch:8.1.1198
vim-patch:8.1.0224
vim-patch:8.0.1299
vim-patch:8.0.0569
vim-patch:8.0.0303
vim-patch:8.0.0296
vim-patch:8.0.0244
vim-patch:8.0.0238
vim-patch:8.0.0232
vim-patch:8.0.0231
vim-patch:8.0.0230
vim-patch:8.0.0210
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4f1709bb1f..ebf5c7a7bc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2732,7 +2732,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * Using inserted text works differently, because the register includes * special characters (newlines, etc.). */ - if (regname == '.') { + if (regname == '.' && !reg) { bool non_linewise_vis = (VIsual_active && VIsual_mode != 'V'); // PUT_LINE has special handling below which means we use 'i' to start. @@ -2815,7 +2815,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * For special registers '%' (file name), '#' (alternate file name) and * ':' (last command line), etc. we have to create a fake yank register. */ - if (get_spec_reg(regname, &insert_string, &allocated, true)) { + if (!reg && get_spec_reg(regname, &insert_string, &allocated, true)) { if (insert_string == NULL) { return; } @@ -5675,6 +5675,71 @@ end: return target; } +/// @param[out] reg Expected to be empty +bool prepare_yankreg_from_object(yankreg_T *reg, String regtype, size_t lines) +{ + if (regtype.size > 1) { + return false; + } + char type = regtype.data ? regtype.data[0] : NUL; + + switch (type) { + case 0: + reg->y_type = kMTUnknown; + break; + case 'v': case 'c': + reg->y_type = kMTCharWise; + break; + case 'V': case 'l': + reg->y_type = kMTLineWise; + break; + case 'b': case Ctrl_V: + reg->y_type = kMTBlockWise; + break; + default: + return false; + } + + reg->y_array = xcalloc(lines, sizeof(uint8_t *)); + reg->y_size = lines; + reg->additional_data = NULL; + reg->timestamp = 0; + return true; +} + +void finish_yankreg_from_object(yankreg_T *reg, bool clipboard_adjust) +{ + 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 != kMTCharWise) { + if (reg->y_type == kMTUnknown || clipboard_adjust) { + xfree(reg->y_array[reg->y_size-1]); + reg->y_size--; + } + if (reg->y_type == kMTUnknown) { + reg->y_type = kMTLineWise; + } + } + } else { + if (reg->y_type == kMTUnknown) { + reg->y_type = kMTCharWise; + } + } + + if (reg->y_type == kMTBlockWise) { + size_t maxlen = 0; + for (size_t i = 0; i < reg->y_size; i++) { + size_t rowlen = STRLEN(reg->y_array[i]); + if (rowlen > maxlen) { + maxlen = rowlen; + } + } + assert(maxlen <= INT_MAX); + reg->y_width = (int)maxlen - 1; + } +} + static bool get_clipboard(int name, yankreg_T **target, bool quiet) { // show message on error |