From 941b02af4cca9fb98c6ee4a8dd4aa800bd337deb Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 8 Apr 2015 21:46:12 +0200 Subject: clipboard: adjust v:register when clipboard=unnamed Helped-By: Nicolas Hillegeer Helped-By: Michael Reed --- src/nvim/normal.c | 2 +- src/nvim/ops.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index be52d6294a..4fcf6f9594 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -914,7 +914,7 @@ getcount: && !oap->op_type && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) { clearop(oap); - set_reg_var(0); + set_reg_var(get_default_register_name()); } /* Get the length of mapped chars again after typing a count, second diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4c5a002f81..54c2edf4fa 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5310,7 +5310,28 @@ static void free_register(struct yankreg *reg) y_current = curr; } -// return target register +/// Check if the default register (used in an unnamed paste) should be a +/// clipboard register. This happens when `clipboard=unnamed[plus]` is set +/// and a provider is available. +/// +/// @returns the name of of a clipboard register that should be used, or `NUL` if none. +int get_default_register_name(void) +{ + int name = NUL; + adjust_clipboard_name(&name, true, false); + return name; +} + +/// Determine if register `*name` should be used as a clipboard. +/// In an unnammed operation, `*name` is `NUL` and will be adjusted to `'*'/'+'` if +/// `clipboard=unnamed[plus]` is set. +/// +/// @param name The name of register, or `NUL` if unnamed. +/// @param quiet Suppress error messages +/// @param writing if we're setting the contents of the clipboard +/// +/// @returns the yankreg that should be used, or `NULL` +/// if the register isn't a clipboard or provider isn't available. static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing) { if (*name == '*' || *name == '+') { if(!eval_has_provider("clipboard")) { -- cgit From 9978a01faa14f46f059119ae8bac6a2be944394d Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 8 Apr 2015 21:47:24 +0200 Subject: clipboard: fix "" register not updated when clipboard=unnamed Helped-By: Scott Prager --- src/nvim/ops.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 54c2edf4fa..1ed6827a33 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -775,9 +775,12 @@ void get_yank_register(int regname, int mode) { int i; + if (mode == YREG_PASTE && get_clipboard(regname, &y_current, false)) { + // y_current is set to clipboard contents. + return; + } y_append = FALSE; - int unnamedclip = cb_flags & CB_UNNAMEDMASK; - if ((regname == 0 || regname == '"') && !unnamedclip && mode != YREG_YANK && y_previous != NULL) { + if ((regname == 0 || regname == '"') && mode != YREG_YANK && y_previous != NULL) { y_current = y_previous; return; } @@ -801,8 +804,6 @@ void get_yank_register(int regname, int mode) if (mode == YREG_YANK) { // remember the written register for unnamed paste y_previous = y_current; - } else if (mode == YREG_PASTE) { - get_clipboard(regname, &y_current, false); } } @@ -5366,11 +5367,11 @@ static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing return NULL; } -static void get_clipboard(int name, struct yankreg** target, bool quiet) +static bool get_clipboard(int name, struct yankreg** target, bool quiet) { struct yankreg* reg = adjust_clipboard_name(&name, quiet, false); if (reg == NULL) { - return; + return false; } free_register(reg); @@ -5455,7 +5456,7 @@ static void get_clipboard(int name, struct yankreg** target, bool quiet) } *target = reg; - return; + return true; err: if (reg->y_array) { @@ -5467,6 +5468,8 @@ err: reg->y_array = NULL; reg->y_size = 0; EMSG("clipboard: provider returned invalid data"); + *target = reg; + return false; } static void set_clipboard(int name) -- cgit From a6487ae9cb4fd510497755ee56cd68a8ab05cbaa Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 9 Apr 2015 20:25:41 +0200 Subject: ops.c: cleanup of `get_yank_register` --- src/nvim/ops.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 1ed6827a33..6c67063739 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -79,7 +79,7 @@ static struct yankreg { } y_regs[NUM_REGISTERS]; static struct yankreg *y_current; /* ptr to current yankreg */ -static int y_append; /* TRUE when appending */ +static bool y_append; /* true when appending */ static struct yankreg *y_previous = NULL; /* ptr to last written yankreg */ static bool clipboard_didwarn_unnamed = false; @@ -773,34 +773,32 @@ typedef enum { /// Obtain the location that would be read when pasting `regname`. void get_yank_register(int regname, int mode) { - int i; + y_append = false; if (mode == YREG_PASTE && get_clipboard(regname, &y_current, false)) { // y_current is set to clipboard contents. return; - } - y_append = FALSE; - if ((regname == 0 || regname == '"') && mode != YREG_YANK && y_previous != NULL) { + } else if (mode != YREG_YANK && (regname == 0 || regname == '"') && y_previous != NULL) { y_current = y_previous; return; } - i = regname; - if (VIM_ISDIGIT(i)) - i -= '0'; - else if (ASCII_ISLOWER(i)) - i = CharOrdLow(i) + 10; - else if (ASCII_ISUPPER(i)) { - i = CharOrdUp(i) + 10; - y_append = TRUE; + + int i = 0; // when not 0-9, a-z, A-Z or '-'/'+'/'*': use register 0 + if (VIM_ISDIGIT(regname)) + i = regname - '0'; + else if (ASCII_ISLOWER(regname)) + i = CharOrdLow(regname) + 10; + else if (ASCII_ISUPPER(regname)) { + i = CharOrdUp(regname) + 10; + y_append = true; } else if (regname == '-') i = DELETION_REGISTER; else if (regname == '*') i = STAR_REGISTER; else if (regname == '+') i = PLUS_REGISTER; - else /* not 0-9, a-z, A-Z or '-': use register 0 */ - i = 0; y_current = &(y_regs[i]); + if (mode == YREG_YANK) { // remember the written register for unnamed paste y_previous = y_current; -- cgit