aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/terminal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r--src/nvim/terminal.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 50574b292d..a52a34cd66 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -37,45 +37,57 @@
// Some code from pangoterm http://www.leonerd.org.uk/code/pangoterm
#include <assert.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <vterm.h>
+#include <vterm_keycodes.h>
+#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
#include "nvim/change.h"
+#include "nvim/channel.h"
#include "nvim/cursor.h"
+#include "nvim/drawline.h"
#include "nvim/drawscreen.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
#include "nvim/event/loop.h"
+#include "nvim/event/multiqueue.h"
#include "nvim/event/time.h"
-#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/highlight.h"
#include "nvim/highlight_group.h"
#include "nvim/keycodes.h"
-#include "nvim/log.h"
#include "nvim/macros.h"
#include "nvim/main.h"
#include "nvim/map.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
-#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
+#include "nvim/msgpack_rpc/channel_defs.h"
+#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/optionstr.h"
-#include "nvim/os/input.h"
+#include "nvim/pos.h"
+#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/terminal.h"
+#include "nvim/types.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
-#include "nvim/window.h"
typedef struct terminal_state {
VimState state;
@@ -375,7 +387,7 @@ void terminal_check_size(Terminal *term)
// Check if there is a window that displays the terminal and find the maximum width and height.
// Skip the autocommand window which isn't actually displayed.
FOR_ALL_TAB_WINDOWS(tp, wp) {
- if (wp == aucmd_win) {
+ if (is_aucmd_win(wp)) {
continue;
}
if (wp->w_buffer && wp->w_buffer->terminal == term) {
@@ -423,12 +435,12 @@ bool terminal_enter(void)
handle_T save_curwin = curwin->handle;
bool save_w_p_cul = curwin->w_p_cul;
char *save_w_p_culopt = NULL;
- char_u save_w_p_culopt_flags = curwin->w_p_culopt_flags;
+ uint8_t save_w_p_culopt_flags = curwin->w_p_culopt_flags;
int save_w_p_cuc = curwin->w_p_cuc;
long save_w_p_so = curwin->w_p_so;
long save_w_p_siso = curwin->w_p_siso;
if (curwin->w_p_cul && curwin->w_p_culopt_flags & CULOPT_NBR) {
- if (strcmp(curwin->w_p_culopt, "number")) {
+ if (strcmp(curwin->w_p_culopt, "number") != 0) {
save_w_p_culopt = curwin->w_p_culopt;
curwin->w_p_culopt = xstrdup("number");
}
@@ -523,6 +535,18 @@ static int terminal_check(VimState *state)
if (must_redraw) {
update_screen();
+
+ // Make sure an invoked autocmd doesn't delete the buffer (and the
+ // terminal) under our fingers.
+ curbuf->b_locked++;
+
+ // save and restore curwin and curbuf, in case the autocmd changes them
+ aco_save_T aco;
+ aucmd_prepbuf(&aco, curbuf);
+ apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, false, curbuf);
+ aucmd_restbuf(&aco);
+
+ curbuf->b_locked--;
}
if (need_maketitle) { // Update title in terminal-mode. #7248
@@ -694,7 +718,7 @@ void terminal_paste(long count, char **y_array, size_t y_size)
}
vterm_keyboard_start_paste(curbuf->terminal->vt);
size_t buff_len = strlen(y_array[0]);
- char_u *buff = xmalloc(buff_len);
+ char *buff = xmalloc(buff_len);
for (int i = 0; i < count; i++) { // -V756
// feed the lines to the terminal
for (size_t j = 0; j < y_size; j++) {
@@ -707,18 +731,18 @@ void terminal_paste(long count, char **y_array, size_t y_size)
buff = xrealloc(buff, len);
buff_len = len;
}
- char_u *dst = buff;
- char_u *src = (char_u *)y_array[j];
+ char *dst = buff;
+ char *src = y_array[j];
while (*src != '\0') {
- len = (size_t)utf_ptr2len((char *)src);
- int c = utf_ptr2char((char *)src);
+ len = (size_t)utf_ptr2len(src);
+ int c = utf_ptr2char(src);
if (!is_filter_char(c)) {
memcpy(dst, src, len);
dst += len;
}
src += len;
}
- terminal_send(curbuf->terminal, (char *)buff, (size_t)(dst - buff));
+ terminal_send(curbuf->terminal, buff, (size_t)(dst - buff));
}
}
xfree(buff);
@@ -1415,8 +1439,8 @@ static bool send_mouse_event(Terminal *term, int c)
int direction = c == K_MOUSEDOWN ? MSCR_DOWN : MSCR_UP;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
scroll_redraw(direction, curwin->w_botline - curwin->w_topline);
- } else {
- scroll_redraw(direction, 3L);
+ } else if (p_mousescroll_vert > 0) {
+ scroll_redraw(direction, p_mousescroll_vert);
}
curwin->w_redr_status = true;