diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-09-25 10:30:20 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-10-01 15:22:48 -0300 |
commit | 1143b416ab7d8bb1707dab2be2cd9e191f9a03e4 (patch) | |
tree | a244c0f5a5b8845b4b8d1dc55ef58420ae720658 /src/nvim/getchar.c | |
parent | c1edd0799000956b8bd23cbc49a4b015e117879e (diff) | |
download | rneovim-1143b416ab7d8bb1707dab2be2cd9e191f9a03e4.tar.gz rneovim-1143b416ab7d8bb1707dab2be2cd9e191f9a03e4.tar.bz2 rneovim-1143b416ab7d8bb1707dab2be2cd9e191f9a03e4.zip |
tui: Don't use 'pastetoggle' for automatic pasting
Add a new special key that can be used by UIs to toggle the 'paste' option and
use it in the TUI instead of the user's 'pastetoggle' value.
Close #2843 #2092
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r-- | src/nvim/getchar.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 604425b3ba..990d0fb8e2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -153,6 +153,7 @@ static char_u typebuf_init[TYPELEN_INIT]; /* initial typebuf.tb_buf */ static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */ static int last_recorded_len = 0; /* number of last recorded chars */ +static const uint8_t ui_toggle[] = { K_SPECIAL, KS_EXTRA, KE_PASTE, 0 }; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "getchar.c.generated.h" @@ -1873,14 +1874,15 @@ static int vgetorpeek(int advance) } } - /* Check for match with 'pastetoggle' */ - if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL))) { - for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; - ++mlen) - if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off - + mlen]) - break; - if (p_pt[mlen] == NUL) { /* match */ + // Check for a key that can toggle the 'paste' option + if (mp == NULL && (State & (INSERT|NORMAL))) { + bool match = typebuf_match_len(ui_toggle, &mlen); + if (!match && mlen != typebuf.tb_len && *p_pt != NUL) { + // didn't match ui_toggle_key and didn't try the whole typebuf, + // check the 'pastetoggle' + match = typebuf_match_len(p_pt, &mlen); + } + if (match) { /* write chars to script file(s) */ if (mlen > typebuf.tb_maplen) gotchars(typebuf.tb_buf + typebuf.tb_off @@ -4238,3 +4240,14 @@ static char_u * translate_mapping ( ga_append(&ga, NUL); return (char_u *)(ga.ga_data); } + +static bool typebuf_match_len(const uint8_t *str, int *mlen) +{ + int i; + for (i = 0; i < typebuf.tb_len && str[i]; i++) { + if (str[i] != typebuf.tb_buf[typebuf.tb_off + i]) + break; + } + *mlen = i; + return str[i] == NUL; // matched the whole string +} |