Merge pull request #19584 from bfredl/terminal_c_BSL_c_O

implement <c-\><c-o> key for terminal mode
This commit is contained in:
bfredl
2022-08-02 14:53:20 +02:00
committed by GitHub
10 changed files with 86 additions and 16 deletions

View File

@@ -1223,10 +1223,10 @@ bool edit(int cmdchar, bool startln, long count)
// the value of `restart_edit` before `ex_normal` returns.
restart_edit = 'i';
force_restart_edit = true;
return false;
} else {
terminal_enter();
return terminal_enter();
}
return false;
}
// Don't allow inserting in the sandbox.

View File

@@ -6026,7 +6026,11 @@ int showmode(void)
msg_puts_attr(_(" INSERT"), attr);
} else if (restart_edit == 'I' || restart_edit == 'i'
|| restart_edit == 'a' || restart_edit == 'A') {
msg_puts_attr(_(" (insert)"), attr);
if (curbuf->terminal) {
msg_puts_attr(_(" (terminal)"), attr);
} else {
msg_puts_attr(_(" (insert)"), attr);
}
} else if (restart_edit == 'R') {
msg_puts_attr(_(" (replace)"), attr);
} else if (restart_edit == 'V') {

View File

@@ -211,12 +211,15 @@ void get_mode(char *buf)
buf[i++] = 'o';
// to be able to detect force-linewise/blockwise/charwise operations
buf[i++] = (char)motion_force;
} else if (curbuf->terminal) {
buf[i++] = 't';
if (restart_edit == 'I') {
buf[i++] = 'T';
}
} else if (restart_edit == 'I' || restart_edit == 'R'
|| restart_edit == 'V') {
buf[i++] = 'i';
buf[i++] = (char)restart_edit;
} else if (curbuf->terminal) {
buf[i++] = 't';
}
}

View File

@@ -82,6 +82,7 @@ typedef struct terminal_state {
int save_rd; // saved value of RedrawingDisabled
bool close;
bool got_bsl; // if the last input was <C-\>
bool got_bsl_o; // if left terminal mode with <c-\><c-o>
} TerminalState;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -388,12 +389,11 @@ void terminal_check_size(Terminal *term)
}
/// Implements MODE_TERMINAL state. :help Terminal-mode
void terminal_enter(void)
bool terminal_enter(void)
{
buf_T *buf = curbuf;
assert(buf->terminal); // Should only be called when curbuf has a terminal.
TerminalState state, *s = &state;
memset(s, 0, sizeof(TerminalState));
TerminalState s[1] = { 0 };
s->term = buf->terminal;
stop_insert_mode = false;
@@ -443,7 +443,9 @@ void terminal_enter(void)
s->state.check = terminal_check;
state_enter(&s->state);
restart_edit = 0;
if (!s->got_bsl_o) {
restart_edit = 0;
}
State = save_state;
RedrawingDisabled = s->save_rd;
apply_autocmds(EVENT_TERMLEAVE, NULL, NULL, false, curbuf);
@@ -467,7 +469,11 @@ void terminal_enter(void)
if (curbuf->terminal == s->term && !s->close) {
terminal_check_cursor();
}
unshowmode(true);
if (restart_edit) {
showmode();
} else {
unshowmode(true);
}
ui_busy_stop();
if (s->close) {
bool wipe = s->term->buf_handle != 0;
@@ -477,6 +483,8 @@ void terminal_enter(void)
do_cmdline_cmd("bwipeout!");
}
}
return s->got_bsl_o;
}
static void terminal_check_cursor(void)
@@ -564,6 +572,14 @@ static int terminal_execute(VimState *state, int key)
}
FALLTHROUGH;
case Ctrl_O:
if (s->got_bsl) {
s->got_bsl_o = true;
restart_edit = 'I';
return 0;
}
FALLTHROUGH;
default:
if (key == Ctrl_BSL && !s->got_bsl) {
s->got_bsl = true;