aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-09-25 10:30:20 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-10-01 15:22:48 -0300
commit1143b416ab7d8bb1707dab2be2cd9e191f9a03e4 (patch)
treea244c0f5a5b8845b4b8d1dc55ef58420ae720658 /src
parentc1edd0799000956b8bd23cbc49a4b015e117879e (diff)
downloadrneovim-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')
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/getchar.c29
-rw-r--r--src/nvim/keymap.c1
-rw-r--r--src/nvim/keymap.h3
-rw-r--r--src/nvim/tui/input.c21
5 files changed, 27 insertions, 29 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index a9d371d0eb..9739090d7c 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -302,7 +302,7 @@ getcmdline (
input_enable_events();
do {
c = safe_vgetc();
- } while (c == K_IGNORE);
+ } while (c == K_IGNORE || c == K_PASTE);
input_disable_events();
if (c == K_EVENT) {
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
+}
diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c
index 0c5c24184e..bf4f5e8c4d 100644
--- a/src/nvim/keymap.c
+++ b/src/nvim/keymap.c
@@ -284,6 +284,7 @@ static struct key_name_entry {
{K_SNR, (char_u *)"SNR"},
{K_PLUG, (char_u *)"Plug"},
{K_CURSORHOLD, (char_u *)"CursorHold"},
+ {K_PASTE, (char_u *)"Paste"},
{0, NULL}
};
diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h
index 38b96b1b8c..119bff943a 100644
--- a/src/nvim/keymap.h
+++ b/src/nvim/keymap.h
@@ -247,6 +247,8 @@ enum key_extra {
, KE_FOCUSGAINED /* focus gained */
, KE_FOCUSLOST /* focus lost */
, KE_EVENT // event
+ , KE_PASTE // special key to toggle the 'paste' option.
+ // sent only by UIs
};
/*
@@ -437,6 +439,7 @@ enum key_extra {
#define K_CURSORHOLD TERMCAP2KEY(KS_EXTRA, KE_CURSORHOLD)
#define K_EVENT TERMCAP2KEY(KS_EXTRA, KE_EVENT)
+#define K_PASTE TERMCAP2KEY(KS_EXTRA, KE_PASTE)
/* Bits for modifier mask */
/* 0x01 cannot be used, because the modifier must be 0x02 or higher */
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 6c362540d0..55c834542f 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -9,7 +9,7 @@
#include "nvim/os/input.h"
#include "nvim/event/rstream.h"
-#define PASTETOGGLE_KEY "<f37>"
+#define PASTETOGGLE_KEY "<Paste>"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/input.c.generated.h"
@@ -34,11 +34,6 @@ void term_input_init(TermInput *input, Loop *loop)
rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff, input);
// initialize a timer handle for handling ESC with libtermkey
time_watcher_init(loop, &input->timer_handle, input);
- // Set the pastetoggle option to a special key that will be sent when
- // \e[20{0,1}~/ are received
- Error err = ERROR_INIT;
- vim_set_option(cstr_as_string("pastetoggle"),
- STRING_OBJ(cstr_as_string(PASTETOGGLE_KEY)), &err);
}
void term_input_destroy(TermInput *input)
@@ -230,20 +225,6 @@ static bool handle_bracketed_paste(TermInput *input)
if (input->paste_enabled == enable) {
return true;
}
- if (enable) {
- // Get the current mode
- int state = get_real_state();
- if (state & NORMAL) {
- // Enter insert mode
- enqueue_input("i", 1);
- } else if (state & VISUAL) {
- // Remove the selected text and enter insert mode
- enqueue_input("c", 1);
- } else if (!(state & INSERT)) {
- // Don't mess with the paste option
- return true;
- }
- }
enqueue_input(PASTETOGGLE_KEY, sizeof(PASTETOGGLE_KEY) - 1);
input->paste_enabled = enable;
return true;