mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 11:38:31 +00:00
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.
This commit is contained in:
@@ -2940,12 +2940,13 @@ do_map (
|
|||||||
if (!did_it) {
|
if (!did_it) {
|
||||||
retval = 2; /* no match */
|
retval = 2; /* no match */
|
||||||
} else if (*keys == Ctrl_C) {
|
} else if (*keys == Ctrl_C) {
|
||||||
/* If CTRL-C has been unmapped, reuse it for Interrupting. */
|
// If CTRL-C has been unmapped, reuse it for Interrupting.
|
||||||
if (map_table == curbuf->b_maphash)
|
if (map_table == curbuf->b_maphash) {
|
||||||
curbuf->b_mapped_ctrl_c &= ~mode;
|
curbuf->b_mapped_ctrl_c &= ~mode;
|
||||||
else
|
} else {
|
||||||
mapped_ctrl_c &= ~mode;
|
mapped_ctrl_c &= ~mode;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2971,11 +2972,12 @@ do_map (
|
|||||||
|
|
||||||
// If CTRL-C has been mapped, don't always use it for Interrupting.
|
// If CTRL-C has been mapped, don't always use it for Interrupting.
|
||||||
if (*keys == Ctrl_C) {
|
if (*keys == Ctrl_C) {
|
||||||
if (map_table == curbuf->b_maphash)
|
if (map_table == curbuf->b_maphash) {
|
||||||
curbuf->b_mapped_ctrl_c |= mode;
|
curbuf->b_mapped_ctrl_c |= mode;
|
||||||
else
|
} else {
|
||||||
mapped_ctrl_c |= mode;
|
mapped_ctrl_c |= mode;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mp->m_keys = vim_strsave(keys);
|
mp->m_keys = vim_strsave(keys);
|
||||||
mp->m_str = vim_strsave(rhs);
|
mp->m_str = vim_strsave(rhs);
|
||||||
|
@@ -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 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 */
|
EXTERN cmdmod_T cmdmod; /* Ex command modifiers */
|
||||||
|
|
||||||
|
@@ -77,9 +77,7 @@
|
|||||||
typedef struct terminal_state {
|
typedef struct terminal_state {
|
||||||
VimState state;
|
VimState state;
|
||||||
Terminal *term;
|
Terminal *term;
|
||||||
int save_state; // saved value of State
|
|
||||||
int save_rd; // saved value of RedrawingDisabled
|
int save_rd; // saved value of RedrawingDisabled
|
||||||
int save_mapped_ctrl_c; // saved value of mapped_ctrl_c;
|
|
||||||
bool close;
|
bool close;
|
||||||
bool got_bs; // if the last input was <C-\>
|
bool got_bs; // if the last input was <C-\>
|
||||||
} TerminalState;
|
} TerminalState;
|
||||||
@@ -362,12 +360,11 @@ void terminal_enter(void)
|
|||||||
|
|
||||||
checkpcmark();
|
checkpcmark();
|
||||||
setpcmark();
|
setpcmark();
|
||||||
s->save_state = State;
|
int save_state = State;
|
||||||
s->save_rd = RedrawingDisabled;
|
s->save_rd = RedrawingDisabled;
|
||||||
State = TERM_FOCUS;
|
State = TERM_FOCUS;
|
||||||
|
mapped_ctrl_c |= TERM_FOCUS; // Always map CTRL-C to avoid interrupt.
|
||||||
RedrawingDisabled = false;
|
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
|
// go to the bottom when the terminal is focused
|
||||||
adjust_topline(s->term, buf, false);
|
adjust_topline(s->term, buf, false);
|
||||||
// erase the unfocused cursor
|
// erase the unfocused cursor
|
||||||
@@ -380,11 +377,10 @@ void terminal_enter(void)
|
|||||||
state_enter(&s->state);
|
state_enter(&s->state);
|
||||||
|
|
||||||
restart_edit = 0;
|
restart_edit = 0;
|
||||||
State = s->save_state;
|
State = save_state;
|
||||||
RedrawingDisabled = s->save_rd;
|
RedrawingDisabled = s->save_rd;
|
||||||
// draw the unfocused cursor
|
// draw the unfocused cursor
|
||||||
invalidate_terminal(s->term, s->term->cursor.row, s->term->cursor.row + 1);
|
invalidate_terminal(s->term, s->term->cursor.row, s->term->cursor.row + 1);
|
||||||
mapped_ctrl_c = s->save_mapped_ctrl_c;
|
|
||||||
unshowmode(true);
|
unshowmode(true);
|
||||||
redraw(curbuf->handle != s->term->buf_handle);
|
redraw(curbuf->handle != s->term->buf_handle);
|
||||||
ui_busy_stop();
|
ui_busy_stop();
|
||||||
|
@@ -21,7 +21,7 @@ describe('mapping', function()
|
|||||||
vim ]])
|
vim ]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with Ctrl-c in Insert mode', function()
|
it('Ctrl-c works in Insert mode', function()
|
||||||
-- Mapping of ctrl-c in insert mode
|
-- Mapping of ctrl-c in insert mode
|
||||||
execute('set cpo-=< cpo-=k')
|
execute('set cpo-=< cpo-=k')
|
||||||
execute('inoremap <c-c> <ctrl-c>')
|
execute('inoremap <c-c> <ctrl-c>')
|
||||||
@@ -41,16 +41,13 @@ describe('mapping', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with Ctrl-c in Visual mode', function()
|
it('Ctrl-c works in Visual mode', function()
|
||||||
-- Mapping of ctrl-c in Visual mode.
|
execute([[vnoremap <c-c> :<C-u>$put ='vmap works'<cr>]])
|
||||||
execute([[vnoremap <c-c> :<C-u>$put ='vmap works']])
|
|
||||||
feed('GV')
|
feed('GV')
|
||||||
-- For some reason the mapping is only triggered when <C-c> is entered in a
|
-- XXX: For some reason the mapping is only triggered
|
||||||
-- separate feed command.
|
-- when <C-c> is in a separate feed command.
|
||||||
wait()
|
wait()
|
||||||
feed('<c-c>')
|
feed('<c-c>')
|
||||||
wait()
|
|
||||||
feed('<cr>')
|
|
||||||
execute('vunmap <c-c>')
|
execute('vunmap <c-c>')
|
||||||
|
|
||||||
expect([[
|
expect([[
|
||||||
@@ -58,7 +55,7 @@ describe('mapping', function()
|
|||||||
vmap works]])
|
vmap works]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with Ctrl-c in Insert mode with langmap', function()
|
it('langmap', function()
|
||||||
-- langmap should not get remapped in insert mode.
|
-- langmap should not get remapped in insert mode.
|
||||||
execute('inoremap { FAIL_ilangmap')
|
execute('inoremap { FAIL_ilangmap')
|
||||||
execute('set langmap=+{ langnoremap')
|
execute('set langmap=+{ langnoremap')
|
||||||
|
Reference in New Issue
Block a user