diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/message.c | 11 | ||||
-rw-r--r-- | src/nvim/move.c | 9 | ||||
-rw-r--r-- | src/nvim/screen.c | 179 |
4 files changed, 76 insertions, 125 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 5d67f53ec4..c0dea196fb 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -300,7 +300,7 @@ int main(int argc, char **argv) assert(p_ch >= 0 && Rows >= p_ch && Rows - p_ch <= INT_MAX); cmdline_row = (int)(Rows - p_ch); msg_row = cmdline_row; - screenalloc(false); // allocate screen buffers + screenalloc(); // allocate screen buffers set_init_2(headless_mode); TIME_MSG("inits 2"); diff --git a/src/nvim/message.c b/src/nvim/message.c index 4552999256..971a14974c 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -946,9 +946,9 @@ void wait_return(int redraw) c = CAR; /* no need for a return in ex mode */ got_int = FALSE; } else { - /* Make sure the hit-return prompt is on screen when 'guioptions' was - * just changed. */ - screenalloc(false); + // Make sure the hit-return prompt is on screen when 'guioptions' was + // just changed. + screenalloc(); State = HITRETURN; setmouse(); @@ -2392,9 +2392,8 @@ static int do_more_prompt(int typed_char) mp_last = msg_sb_start(mp_last->sb_prev); } - if (toscroll == -1 - && grid_ins_lines(&default_grid, 0, 1, (int)Rows, - 0, (int)Columns) == OK) { + if (toscroll == -1) { + grid_ins_lines(&default_grid, 0, 1, (int)Rows, 0, (int)Columns); grid_fill(&default_grid, 0, 1, 0, (int)Columns, ' ', ' ', 0); // display line at top (void)disp_sb_line(0, mp); diff --git a/src/nvim/move.c b/src/nvim/move.c index 610fd04ebc..7aa7f922c1 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -152,7 +152,7 @@ void update_topline(void) // If there is no valid screen and when the window height is zero just use // the cursor line. - if (!screen_valid(true) || curwin->w_height_inner == 0) { + if (!default_grid.chars || curwin->w_height_inner == 0) { curwin->w_topline = curwin->w_cursor.lnum; curwin->w_botline = curwin->w_topline; curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; @@ -925,12 +925,9 @@ void curs_columns( curwin->w_wrow -= extra; } + // extra could be either positive or negative extra = ((int)prev_skipcol - (int)curwin->w_skipcol) / width; - if (extra > 0) { - win_ins_lines(curwin, 0, extra); - } else if (extra < 0) { - win_del_lines(curwin, 0, -extra); - } + win_scroll_lines(curwin, 0, extra); } else { curwin->w_skipcol = 0; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 00d7c05be4..aa2982ec0c 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -274,9 +274,10 @@ void update_screen(int type) static int did_intro = FALSE; int did_one; - /* Don't do anything if the screen structures are (not yet) valid. */ - if (!screen_valid(TRUE)) + // Don't do anything if the screen structures are (not yet) valid. + if (!default_grid.chars) { return; + } if (must_redraw) { if (type < must_redraw) /* use maximal type */ @@ -335,10 +336,8 @@ void update_screen(int type) type = CLEAR; } else if (type != CLEAR) { check_for_delay(false); - if (grid_ins_lines(&default_grid, 0, msg_scrolled, (int)Rows, - 0, (int)Columns) == FAIL) { - type = CLEAR; - } + grid_ins_lines(&default_grid, 0, msg_scrolled, (int)Rows, + 0, (int)Columns); FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_winrow < msg_scrolled) { if (W_ENDROW(wp) > msg_scrolled @@ -828,31 +827,31 @@ static void win_update(win_T *wp) // Try to insert the correct number of lines. // If not the last window, delete the lines at the bottom. // win_ins_lines may fail when the terminal can't do it. - if (win_ins_lines(wp, 0, i) == OK) { - if (wp->w_lines_valid != 0) { - /* Need to update rows that are new, stop at the - * first one that scrolled down. */ - top_end = i; - scrolled_down = TRUE; - - /* Move the entries that were scrolled, disable - * the entries for the lines to be redrawn. */ - if ((wp->w_lines_valid += j) > wp->w_grid.Rows) { - wp->w_lines_valid = wp->w_grid.Rows; - } - for (idx = wp->w_lines_valid; idx - j >= 0; idx--) { - wp->w_lines[idx] = wp->w_lines[idx - j]; - } - while (idx >= 0) { - wp->w_lines[idx--].wl_valid = false; - } + win_scroll_lines(wp, 0, i); + if (wp->w_lines_valid != 0) { + // Need to update rows that are new, stop at the + // first one that scrolled down. + top_end = i; + scrolled_down = true; + + // Move the entries that were scrolled, disable + // the entries for the lines to be redrawn. + if ((wp->w_lines_valid += j) > wp->w_grid.Rows) { + wp->w_lines_valid = wp->w_grid.Rows; } - } else - mid_start = 0; /* redraw all lines */ - } else - mid_start = 0; /* redraw all lines */ - } else - mid_start = 0; /* redraw all lines */ + for (idx = wp->w_lines_valid; idx - j >= 0; idx--) { + wp->w_lines[idx] = wp->w_lines[idx - j]; + } + while (idx >= 0) { + wp->w_lines[idx--].wl_valid = false; + } + } + } else { + mid_start = 0; // redraw all lines + } + } else { + mid_start = 0; // redraw all lines + } } else { /* * New topline is at or below old topline: May scroll up. @@ -889,11 +888,8 @@ static void win_update(win_T *wp) /* ... but don't delete new filler lines. */ row -= wp->w_topfill; if (row > 0) { - if (win_del_lines(wp, 0, row) == OK) { - bot_start = wp->w_grid.Rows - row; - } else { - mid_start = 0; // redraw all lines - } + win_scroll_lines(wp, 0, -row); + bot_start = wp->w_grid.Rows - row; } if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) { /* @@ -1148,7 +1144,7 @@ static void win_update(win_T *wp) // Update a line when it is in an area that needs updating, when it // has changes or w_lines[idx] is invalid. // "bot_start" may be halfway a wrapped line after using - // win_del_lines(), check if the current line includes it. + // win_scroll_lines(), check if the current line includes it. // When syntax folding is being used, the saved syntax states will // already have been updated, we can't see where the syntax state is // the same again, just update until the end of the window. @@ -1244,11 +1240,8 @@ static void win_update(win_T *wp) if (row - xtra_rows >= wp->w_grid.Rows - 2) { mod_bot = MAXLNUM; } else { - if (win_del_lines(wp, row, -xtra_rows) == FAIL) { - mod_bot = MAXLNUM; - } else { - bot_start = wp->w_grid.Rows + xtra_rows; - } + win_scroll_lines(wp, row, xtra_rows); + bot_start = wp->w_grid.Rows + xtra_rows; } } else if (xtra_rows > 0) { /* May scroll text down. If there is not enough @@ -1257,9 +1250,8 @@ static void win_update(win_T *wp) if (row + xtra_rows >= wp->w_grid.Rows - 2) { mod_bot = MAXLNUM; } else { - if (win_ins_lines(wp, row + old_rows, xtra_rows) == FAIL) { - mod_bot = MAXLNUM; - } else if (top_end > row + old_rows) { + win_scroll_lines(wp, row + old_rows, xtra_rows); + if (top_end > row + old_rows) { // Scrolled the part at the top that requires // updating down. top_end += xtra_rows; @@ -5813,7 +5805,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, } // nothing to do - if (grid->chars == NULL || start_row >= end_row || start_col >= end_col) { + if (start_row >= end_row || start_col >= end_col) { return; } @@ -5902,18 +5894,6 @@ void check_for_delay(int check_msg_scroll) } } -/* - * screen_valid - allocate screen buffers if size changed - * If "doclear" is TRUE: clear screen if it has been resized. - * Returns TRUE if there is a valid screen to write to. - * Returns FALSE when starting up and screen not initialized yet. - */ -int screen_valid(int doclear) -{ - screenalloc(doclear); // allocate screen buffers if size changed - return default_grid.chars != NULL; -} - /// (Re)allocates a window grid if size changed while in ext_multigrid mode. /// Updates size, offsets and handle for the grid regardless. /// @@ -5989,7 +5969,7 @@ void grid_assign_handle(ScreenGrid *grid) /// default_grid.Columns to access items in default_grid.chars[]. Use Rows /// and Columns for positioning text etc. where the final size of the shell is /// needed. -void screenalloc(bool doclear) +void screenalloc(void) { static bool entered = false; // avoid recursiveness int retry_count = 0; @@ -6041,7 +6021,7 @@ retry: // Continuing with the old arrays may result in a crash, because the // size is wrong. - grid_alloc(&default_grid, Rows, Columns, !doclear, true); + grid_alloc(&default_grid, Rows, Columns, true, true); StlClickDefinition *new_tab_page_click_defs = xcalloc( (size_t)Columns, sizeof(*new_tab_page_click_defs)); @@ -6055,10 +6035,7 @@ retry: default_grid.col_offset = 0; default_grid.handle = DEFAULT_GRID_HANDLE; - must_redraw = CLEAR; /* need to clear the screen later */ - if (doclear) - screenclear2(); - + must_redraw = CLEAR; // need to clear the screen later entered = FALSE; --RedrawingDisabled; @@ -6165,13 +6142,9 @@ void clear_tab_page_click_defs(StlClickDefinition *const tpcd, void screenclear(void) { - check_for_delay(FALSE); - screenalloc(false); /* allocate screen buffers if size changed */ - screenclear2(); /* clear the screen */ -} + check_for_delay(false); + screenalloc(); // allocate screen buffers if size changed -static void screenclear2(void) -{ int i; if (starting == NO_SCREEN || default_grid.chars == NULL) { @@ -6265,42 +6238,28 @@ void setcursor(void) } } -/// Insert 'line_count' lines at 'row' in window 'wp'. -/// Returns FAIL if the lines are not inserted, OK for success. -int win_ins_lines(win_T *wp, int row, int line_count) -{ - return win_do_lines(wp, row, line_count, false); -} - -/// Delete "line_count" window lines at "row" in window "wp". -/// Return OK for success, FAIL if the lines are not deleted. -int win_del_lines(win_T *wp, int row, int line_count) -{ - return win_do_lines(wp, row, line_count, true); -} - -// Common code for win_ins_lines() and win_del_lines(). -// Returns OK or FAIL when the work has been done. -static int win_do_lines(win_T *wp, int row, int line_count, int del) +/// Scroll 'line_count' lines at 'row' in window 'wp'. +/// +/// Positive `line_count' means scrolling down, so that more space is available +/// at 'row'. Negative `line_count` implies deleting lines at `row`. +void win_scroll_lines(win_T *wp, int row, int line_count) { - if (!redrawing() || line_count <= 0) { - return FAIL; + if (!redrawing() || line_count == 0) { + return; } // No lines are being moved, just draw over the entire area - if (row + line_count >= wp->w_grid.Rows) { - return OK; + if (row + abs(line_count) >= wp->w_grid.Rows) { + return; } - int retval; - if (del) { - retval = grid_del_lines(&wp->w_grid, row, line_count, - wp->w_grid.Rows, 0, wp->w_grid.Columns); + if (line_count < 0) { + grid_del_lines(&wp->w_grid, row, -line_count, + wp->w_grid.Rows, 0, wp->w_grid.Columns); } else { - retval = grid_ins_lines(&wp->w_grid, row, line_count, - wp->w_grid.Rows, 0, wp->w_grid.Columns); + grid_ins_lines(&wp->w_grid, row, line_count, + wp->w_grid.Rows, 0, wp->w_grid.Columns); } - return retval; } /* @@ -6320,10 +6279,8 @@ static int win_do_lines(win_T *wp, int row, int line_count, int del) /// 'col' is the column from with we start inserting. // /// 'row', 'col' and 'end' are relative to the start of the region. -/// -/// @return FAIL for failure, OK for success. -int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, - int width) +void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, + int width) { int i; int j; @@ -6334,8 +6291,8 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, row += row_off; end += row_off; - if (!screen_valid(TRUE) || line_count <= 0) { - return FAIL; + if (line_count <= 0) { + return; } // Shift line_offset[] line_count down to reflect the inserted lines. @@ -6365,17 +6322,15 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, ui_call_grid_scroll(grid->handle, row, end, col, col+width, -line_count, 0); - return OK; + return; } /// delete lines on the screen and move lines up. /// 'end' is the line after the scrolled part. Normally it is Rows. /// When scrolling region used 'off' is the offset from the top for the region. /// 'row' and 'end' are relative to the start of the region. -/// -/// Return OK for success, FAIL if the lines are not deleted. -int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, - int width) +void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, + int width) { int j; int i; @@ -6386,8 +6341,8 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, row += row_off; end += row_off; - if (!screen_valid(TRUE) || line_count <= 0) { - return FAIL; + if (line_count <= 0) { + return; } // Now shift line_offset[] line_count up to reflect the deleted lines. @@ -6418,7 +6373,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, ui_call_grid_scroll(grid->handle, row, end, col, col+width, line_count, 0); - return OK; + return; } @@ -7186,7 +7141,7 @@ void screen_resize(int width, int height) */ if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM || exmode_active) { - screenalloc(false); + screenalloc(); repeat_message(); } else { if (curwin->w_p_scb) |