diff options
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | src/nvim/screen.c | 98 | ||||
-rw-r--r-- | src/nvim/term.c | 100 |
5 files changed, 103 insertions, 101 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 706aef0133..db95399285 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6446,7 +6446,7 @@ static void ex_winsize(exarg_T *eap) p = arg; h = getdigits(&arg); if (*p != NUL && *arg == NUL) - set_shellsize(w, h, TRUE); + screen_resize(w, h, TRUE); else EMSG(_("E465: :winsize requires two number arguments")); } diff --git a/src/nvim/main.c b/src/nvim/main.c index 54077acfe3..99d4e18546 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -281,7 +281,7 @@ int main(int argc, char **argv) // In embedded mode don't do terminal-related initializations, assume an // initial screen size of 80x20 full_screen = true; - set_shellsize(80, 20, false); + screen_resize(80, 20, false); } else { // set terminal name and get terminal capabilities (will set full_screen) // Do some initialization of the screen diff --git a/src/nvim/option.c b/src/nvim/option.c index ee70b5bf8a..79ded9f32f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5540,7 +5540,7 @@ set_num_option ( *pp = old_value; else if (full_screen ) - set_shellsize((int)Columns, (int)Rows, TRUE); + screen_resize((int)Columns, (int)Rows, TRUE); else { /* Postpone the resizing; check the size and cmdline position for * messages. */ diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 2dbf3f8888..0225eb72c1 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -103,6 +103,7 @@ #include "nvim/ex_cmds.h" #include "nvim/ex_cmds2.h" #include "nvim/ex_getln.h" +#include "nvim/edit.h" #include "nvim/farsi.h" #include "nvim/fileio.h" #include "nvim/fold.h" @@ -120,6 +121,7 @@ #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/popupmnu.h" #include "nvim/quickfix.h" @@ -129,6 +131,7 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/term.h" +#include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" @@ -8117,3 +8120,98 @@ int screen_screenrow(void) return screen_cur_row; } +/* + * Set size of the Vim shell. + * If 'mustset' is TRUE, we must set Rows and Columns, do not get the real + * window size (this is used for the :win command). + * If 'mustset' is FALSE, we may try to get the real window size and if + * it fails use 'width' and 'height'. + */ +void screen_resize(int width, int height, int mustset) +{ + static int busy = FALSE; + + /* + * Avoid recursiveness, can happen when setting the window size causes + * another window-changed signal. + */ + if (busy) + return; + + if (width < 0 || height < 0) /* just checking... */ + return; + + if (State == HITRETURN || State == SETWSIZE) { + /* postpone the resizing */ + State = SETWSIZE; + return; + } + + /* curwin->w_buffer can be NULL when we are closing a window and the + * buffer has already been closed and removing a scrollbar causes a resize + * event. Don't resize then, it will happen after entering another buffer. + */ + if (curwin->w_buffer == NULL) + return; + + ++busy; + + + if (mustset || (ui_get_shellsize() == FAIL && height != 0)) { + Rows = height; + Columns = width; + check_shellsize(); + mch_set_shellsize(); + } else + check_shellsize(); + + /* The window layout used to be adjusted here, but it now happens in + * screenalloc() (also invoked from screenclear()). That is because the + * "busy" check above may skip this, but not screenalloc(). */ + + if (State != ASKMORE && State != EXTERNCMD && State != CONFIRM) + screenclear(); + else + screen_start(); /* don't know where cursor is now */ + + if (starting != NO_SCREEN) { + maketitle(); + changed_line_abv_curs(); + invalidate_botline(); + + /* + * We only redraw when it's needed: + * - While at the more prompt or executing an external command, don't + * redraw, but position the cursor. + * - While editing the command line, only redraw that. + * - in Ex mode, don't redraw anything. + * - Otherwise, redraw right now, and position the cursor. + * Always need to call update_screen() or screenalloc(), to make + * sure Rows/Columns and the size of ScreenLines[] is correct! + */ + if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM + || exmode_active) { + screenalloc(false); + repeat_message(); + } else { + if (curwin->w_p_scb) + do_check_scrollbind(TRUE); + if (State & CMDLINE) { + update_screen(NOT_VALID); + redrawcmdline(); + } else { + update_topline(); + if (pum_visible()) { + redraw_later(NOT_VALID); + ins_compl_show_pum(); /* This includes the redraw. */ + } else + update_screen(NOT_VALID); + if (redrawing()) + setcursor(); + } + } + cursor_on(); /* redrawing may have switched it off */ + } + out_flush(); + --busy; +} diff --git a/src/nvim/term.c b/src/nvim/term.c index 9da7e11b96..47f7fa8af3 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -1472,7 +1472,7 @@ int set_termname(char_u *term) width = 80; height = 24; /* most terminals are 24 lines */ } - set_shellsize(width, height, FALSE); /* may change Rows */ + screen_resize(width, height, FALSE); /* may change Rows */ if (starting != NO_SCREEN) { if (scroll_region) scroll_region_reset(); /* In case Rows changed */ @@ -2289,7 +2289,7 @@ void win_new_shellsize(void) */ void shell_resized(void) { - set_shellsize(0, 0, FALSE); + screen_resize(0, 0, FALSE); } /* @@ -2311,102 +2311,6 @@ void shell_resized_check(void) } /* - * Set size of the Vim shell. - * If 'mustset' is TRUE, we must set Rows and Columns, do not get the real - * window size (this is used for the :win command). - * If 'mustset' is FALSE, we may try to get the real window size and if - * it fails use 'width' and 'height'. - */ -void set_shellsize(int width, int height, int mustset) -{ - static int busy = FALSE; - - /* - * Avoid recursiveness, can happen when setting the window size causes - * another window-changed signal. - */ - if (busy) - return; - - if (width < 0 || height < 0) /* just checking... */ - return; - - if (State == HITRETURN || State == SETWSIZE) { - /* postpone the resizing */ - State = SETWSIZE; - return; - } - - /* curwin->w_buffer can be NULL when we are closing a window and the - * buffer has already been closed and removing a scrollbar causes a resize - * event. Don't resize then, it will happen after entering another buffer. - */ - if (curwin->w_buffer == NULL) - return; - - ++busy; - - - if (mustset || (ui_get_shellsize() == FAIL && height != 0)) { - Rows = height; - Columns = width; - check_shellsize(); - mch_set_shellsize(); - } else - check_shellsize(); - - /* The window layout used to be adjusted here, but it now happens in - * screenalloc() (also invoked from screenclear()). That is because the - * "busy" check above may skip this, but not screenalloc(). */ - - if (State != ASKMORE && State != EXTERNCMD && State != CONFIRM) - screenclear(); - else - screen_start(); /* don't know where cursor is now */ - - if (starting != NO_SCREEN) { - maketitle(); - changed_line_abv_curs(); - invalidate_botline(); - - /* - * We only redraw when it's needed: - * - While at the more prompt or executing an external command, don't - * redraw, but position the cursor. - * - While editing the command line, only redraw that. - * - in Ex mode, don't redraw anything. - * - Otherwise, redraw right now, and position the cursor. - * Always need to call update_screen() or screenalloc(), to make - * sure Rows/Columns and the size of ScreenLines[] is correct! - */ - if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM - || exmode_active) { - screenalloc(false); - repeat_message(); - } else { - if (curwin->w_p_scb) - do_check_scrollbind(TRUE); - if (State & CMDLINE) { - update_screen(NOT_VALID); - redrawcmdline(); - } else { - update_topline(); - if (pum_visible()) { - redraw_later(NOT_VALID); - ins_compl_show_pum(); /* This includes the redraw. */ - } else - update_screen(NOT_VALID); - if (redrawing()) - setcursor(); - } - } - cursor_on(); /* redrawing may have switched it off */ - } - out_flush(); - --busy; -} - -/* * Set the terminal to TMODE_RAW (for Normal mode) or TMODE_COOK (for external * commands and Ex mode). */ |