aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/terminal.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-08-03 00:08:17 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-08-03 00:08:17 -0600
commit9449e1b8d273ff78eb894c588110ffa0c17d6ee3 (patch)
tree9e4470c33bd4187d9f42f0b2c4aaa995310c5be8 /src/nvim/terminal.c
parent308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (diff)
parentb8dcbcc732baf84fc48d6b272c3ade0bcb129b3b (diff)
downloadrneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.gz
rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.bz2
rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.zip
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r--src/nvim/terminal.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index be49048aec..c23aff00cb 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -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);
@@ -451,7 +453,7 @@ void terminal_enter(void)
if (save_curwin == curwin->handle) { // Else: window was closed.
curwin->w_p_cul = save_w_p_cul;
if (save_w_p_culopt) {
- xfree(curwin->w_p_culopt);
+ free_string_option(curwin->w_p_culopt);
curwin->w_p_culopt = save_w_p_culopt;
}
curwin->w_p_culopt_flags = save_w_p_culopt_flags;
@@ -459,7 +461,7 @@ void terminal_enter(void)
curwin->w_p_so = save_w_p_so;
curwin->w_p_siso = save_w_p_siso;
} else if (save_w_p_culopt) {
- xfree(save_w_p_culopt);
+ free_string_option(save_w_p_culopt);
}
// draw the unfocused cursor
@@ -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;
@@ -1384,7 +1400,7 @@ static void fetch_row(Terminal *term, int row, int end_col)
fetch_cell(term, row, col, &cell);
if (cell.chars[0]) {
int cell_len = 0;
- for (int i = 0; cell.chars[i]; i++) {
+ for (int i = 0; i < VTERM_MAX_CHARS_PER_CELL && cell.chars[i]; i++) {
cell_len += utf_char2bytes((int)cell.chars[i], ptr + cell_len);
}
ptr += cell_len;