From 3dfbeabf35dbfe5494a4adce7b4d94d56bbe0171 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 19 Dec 2015 10:03:17 +0900 Subject: vim-patch:7.4.569/573 vim-patch:7.4.569 vim-patch:7.4.573 Helped-by: @glts https://github.com/neovim/neovim/pull/2621 Problem: Having CTRL-C interrupt or not does not check the mode of the mapping. (Ingo Karkat) Solution: Use a bitmask with the map mode. (Christian Brabandt) https://github.com/vim/vim/commit/651863c94a882a97aec7968fc87a638ff78e56ff Problem: Mapping CTRL-C in Visual mode doesn't work. (Ingo Karkat) Solution: Call get_real_state() instead of using State directly. https://github.com/vim/vim/commit/5000869712f799d9ca25c0e45dc21d332edae5f4 --- src/nvim/buffer_defs.h | 2 ++ src/nvim/getchar.c | 15 +++++++++++---- src/nvim/globals.h | 2 +- src/nvim/misc1.c | 2 +- src/nvim/os/input.c | 3 ++- src/nvim/terminal.c | 4 ++-- src/nvim/version.c | 4 ++-- 7 files changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 6b5bbe3b00..78d9a9484e 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -751,6 +751,8 @@ struct file_buffer { Terminal *terminal; // Terminal instance associated with the buffer dict_T *additional_data; // Additional data from shada file if any. + + int b_mapped_ctrl_c; // modes where CTRL-C is mapped }; /* diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 44d6c086e7..008c6cecd5 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2941,7 +2941,10 @@ do_map ( retval = 2; /* no match */ } else if (*keys == Ctrl_C) { /* If CTRL-C has been unmapped, reuse it for Interrupting. */ - mapped_ctrl_c = FALSE; + if (map_table == curbuf->b_maphash) + curbuf->b_mapped_ctrl_c &= ~mode; + else + mapped_ctrl_c &= ~mode; } goto theend; } @@ -2966,9 +2969,13 @@ do_map ( */ mp = xmalloc(sizeof(mapblock_T)); - /* If CTRL-C has been mapped, don't always use it for Interrupting. */ - if (*keys == Ctrl_C) - mapped_ctrl_c = TRUE; + // If CTRL-C has been mapped, don't always use it for Interrupting. + if (*keys == Ctrl_C) { + if (map_table == curbuf->b_maphash) + curbuf->b_mapped_ctrl_c |= mode; + else + mapped_ctrl_c |= mode; + } mp->m_keys = vim_strsave(keys); mp->m_str = vim_strsave(rhs); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 40994d20b5..da8868d7a0 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -887,7 +887,7 @@ EXTERN int ctrl_x_mode INIT(= 0); /* Which Ctrl-X mode are we in? */ EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */ -EXTERN int mapped_ctrl_c INIT(= FALSE); /* CTRL-C is mapped */ +EXTERN int mapped_ctrl_c INIT(= 0); /* modes where CTRL-C is mapped */ EXTERN cmdmod_T cmdmod; /* Ex command modifiers */ diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 96ef6cbaef..b2cec82121 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2352,7 +2352,7 @@ int get_keystroke(void) int save_mapped_ctrl_c = mapped_ctrl_c; int waited = 0; - mapped_ctrl_c = FALSE; /* mappings are not used here */ + mapped_ctrl_c = 0; // mappings are not used here for (;; ) { // flush output before waiting ui_flush(); diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index ef6b5ff6f5..e632544856 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -19,6 +19,7 @@ #include "nvim/getchar.h" #include "nvim/main.h" #include "nvim/misc1.h" +#include "nvim/misc2.h" #define READ_BUFFER_SIZE 0xfff #define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4) @@ -357,7 +358,7 @@ static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data, static void process_interrupts(void) { - if (mapped_ctrl_c) { + if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { return; } diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 6045acd1cb..b129a93a05 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -79,7 +79,7 @@ typedef struct terminal_state { Terminal *term; int save_state; // saved value of State int save_rd; // saved value of RedrawingDisabled - bool save_mapped_ctrl_c; // saved value of mapped_ctrl_c; + int save_mapped_ctrl_c; // saved value of mapped_ctrl_c; bool close; bool got_bs; // if the last input was } TerminalState; @@ -367,7 +367,7 @@ void terminal_enter(void) State = TERM_FOCUS; RedrawingDisabled = false; s->save_mapped_ctrl_c = mapped_ctrl_c; - mapped_ctrl_c = true; + mapped_ctrl_c = MAP_ALL_MODES; // go to the bottom when the terminal is focused adjust_topline(s->term, buf, false); // erase the unfocused cursor diff --git a/src/nvim/version.c b/src/nvim/version.c index d0a2771a19..bbe58bafba 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -551,11 +551,11 @@ static int included_patches[] = { 576, 575, 574, - // 573, + 573, 572, // 571 NA // 570 NA - // 569, + 569, 568, 567, 566, -- cgit From 8eeda7169aa47881f0b6d697e291a1ef85c43e4e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 13 Jan 2016 00:39:54 -0500 Subject: terminal: less babysitting of mapped_ctrl_c process_interrupts() checks get_real_state() so we can avoid some housekeeping of mapped_ctrl_c in terminal-mode. --- src/nvim/getchar.c | 12 +++++++----- src/nvim/globals.h | 2 +- src/nvim/terminal.c | 10 +++------- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 008c6cecd5..89d22ad811 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2940,11 +2940,12 @@ do_map ( if (!did_it) { retval = 2; /* no match */ } else if (*keys == Ctrl_C) { - /* If CTRL-C has been unmapped, reuse it for Interrupting. */ - if (map_table == curbuf->b_maphash) + // If CTRL-C has been unmapped, reuse it for Interrupting. + if (map_table == curbuf->b_maphash) { curbuf->b_mapped_ctrl_c &= ~mode; - else + } else { mapped_ctrl_c &= ~mode; + } } goto theend; } @@ -2971,10 +2972,11 @@ do_map ( // If CTRL-C has been mapped, don't always use it for Interrupting. if (*keys == Ctrl_C) { - if (map_table == curbuf->b_maphash) + if (map_table == curbuf->b_maphash) { curbuf->b_mapped_ctrl_c |= mode; - else + } else { mapped_ctrl_c |= mode; + } } mp->m_keys = vim_strsave(keys); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index da8868d7a0..50eda6cb17 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -887,7 +887,7 @@ EXTERN int ctrl_x_mode INIT(= 0); /* Which Ctrl-X mode are we in? */ EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */ -EXTERN int mapped_ctrl_c INIT(= 0); /* modes where CTRL-C is mapped */ +EXTERN int mapped_ctrl_c INIT(= 0); // Modes where CTRL-C is mapped. EXTERN cmdmod_T cmdmod; /* Ex command modifiers */ diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index b129a93a05..0a7807d811 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -77,9 +77,7 @@ typedef struct terminal_state { VimState state; Terminal *term; - int save_state; // saved value of State int save_rd; // saved value of RedrawingDisabled - int save_mapped_ctrl_c; // saved value of mapped_ctrl_c; bool close; bool got_bs; // if the last input was } TerminalState; @@ -362,12 +360,11 @@ void terminal_enter(void) checkpcmark(); setpcmark(); - s->save_state = State; + int save_state = State; s->save_rd = RedrawingDisabled; State = TERM_FOCUS; + mapped_ctrl_c |= TERM_FOCUS; // Always map CTRL-C to avoid interrupt. RedrawingDisabled = false; - s->save_mapped_ctrl_c = mapped_ctrl_c; - mapped_ctrl_c = MAP_ALL_MODES; // go to the bottom when the terminal is focused adjust_topline(s->term, buf, false); // erase the unfocused cursor @@ -380,11 +377,10 @@ void terminal_enter(void) state_enter(&s->state); restart_edit = 0; - State = s->save_state; + State = save_state; RedrawingDisabled = s->save_rd; // draw the unfocused cursor invalidate_terminal(s->term, s->term->cursor.row, s->term->cursor.row + 1); - mapped_ctrl_c = s->save_mapped_ctrl_c; unshowmode(true); redraw(curbuf->handle != s->term->buf_handle); ui_busy_stop(); -- cgit