diff options
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r-- | src/nvim/window.c | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index 72ee400e40..00f49724b6 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -641,7 +641,7 @@ void win_set_minimal_style(win_T *wp) wp->w_p_scl = (char_u *)xstrdup("auto"); } - // foldcolumn: use 'auto' + // foldcolumn: use '0' if (wp->w_p_fdc[0] != '0') { xfree(wp->w_p_fdc); wp->w_p_fdc = (char_u *)xstrdup("0"); @@ -700,9 +700,10 @@ int win_fdccol_count(win_T *wp) const char *fdc = (const char *)wp->w_p_fdc; // auto:<NUM> - if (strncmp(fdc, "auto:", 5) == 0) { + if (strncmp(fdc, "auto", 4) == 0) { + const int fdccol = fdc[4] == ':' ? fdc[5] - '0' : 1; int needed_fdccols = getDeepestNesting(wp); - return MIN(fdc[5] - '0', needed_fdccols); + return MIN(fdccol, needed_fdccols); } else { return fdc[0] - '0'; } @@ -1636,6 +1637,19 @@ bool win_valid(const win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT return false; } +// Find window "handle" in the current tab page. +// Return NULL if not found. +win_T *win_find_by_handle(handle_T handle) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + if (wp->handle == handle) { + return wp; + } + } + return NULL; +} + /// Check if "win" is a pointer to an existing window in any tabpage. /// /// @param win window to check @@ -3787,32 +3801,35 @@ void free_tabpage(tabpage_T *tp) /// @return Was the new tabpage created successfully? FAIL or OK. int win_new_tabpage(int after, char_u *filename) { - tabpage_T *tp = curtab; + tabpage_T *old_curtab = curtab; tabpage_T *newtp; int n; newtp = alloc_tabpage(); - /* Remember the current windows in this Tab page. */ - if (leave_tabpage(curbuf, TRUE) == FAIL) { + // Remember the current windows in this Tab page. + if (leave_tabpage(curbuf, true) == FAIL) { xfree(newtp); return FAIL; } - newtp->tp_localdir = tp->tp_localdir ? vim_strsave(tp->tp_localdir) : NULL; + newtp->tp_localdir = old_curtab->tp_localdir + ? vim_strsave(old_curtab->tp_localdir) : NULL; curtab = newtp; - /* Create a new empty window. */ - if (win_alloc_firstwin(tp->tp_curwin) == OK) { - /* Make the new Tab page the new topframe. */ + // Create a new empty window. + if (win_alloc_firstwin(old_curtab->tp_curwin) == OK) { + // Make the new Tab page the new topframe. if (after == 1) { - /* New tab page becomes the first one. */ + // New tab page becomes the first one. newtp->tp_next = first_tabpage; first_tabpage = newtp; } else { + tabpage_T *tp = old_curtab; + if (after > 0) { - /* Put new tab page before tab page "after". */ + // Put new tab page before tab page "after". n = 2; for (tp = first_tabpage; tp->tp_next != NULL && n < after; tp = tp->tp_next) @@ -3826,13 +3843,13 @@ int win_new_tabpage(int after, char_u *filename) win_comp_scroll(curwin); newtp->tp_topframe = topframe; - last_status(FALSE); + last_status(false); redraw_all_later(NOT_VALID); - tabpage_check_windows(tp); + tabpage_check_windows(old_curtab); - lastused_tabpage = tp; + lastused_tabpage = old_curtab; apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf); @@ -3842,8 +3859,8 @@ int win_new_tabpage(int after, char_u *filename) return OK; } - /* Failed, get back the previous Tab page */ - enter_tabpage(curtab, curbuf, TRUE, TRUE); + // Failed, get back the previous Tab page + enter_tabpage(curtab, curbuf, true, true); return FAIL; } @@ -4523,7 +4540,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, // Might need to scroll the old window before switching, e.g., when the // cursor was moved. - update_topline(); + update_topline(curwin); // may have to copy the buffer options when 'cpo' contains 'S' if (wp->w_buffer != curbuf) { @@ -4996,7 +5013,10 @@ void win_size_save(garray_T *gap) { ga_init(gap, (int)sizeof(int), 1); - ga_grow(gap, win_count() * 2); + ga_grow(gap, win_count() * 2 + 1); + // first entry is value of 'lines' + ((int *)gap->ga_data)[gap->ga_len++] = Rows; + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { ((int *)gap->ga_data)[gap->ga_len++] = wp->w_width + wp->w_vsep_width; @@ -5004,18 +5024,18 @@ void win_size_save(garray_T *gap) } } -/* - * Restore window sizes, but only if the number of windows is still the same. - * Does not free the growarray. - */ +// Restore window sizes, but only if the number of windows is still the same +// and 'lines' didn't change. +// Does not free the growarray. void win_size_restore(garray_T *gap) + FUNC_ATTR_NONNULL_ALL { - if (win_count() * 2 == gap->ga_len) { - /* The order matters, because frames contain other frames, but it's - * difficult to get right. The easy way out is to do it twice. */ - for (int j = 0; j < 2; ++j) - { - int i = 0; + if (win_count() * 2 + 1 == gap->ga_len + && ((int *)gap->ga_data)[0] == Rows) { + // The order matters, because frames contain other frames, but it's + // difficult to get right. The easy way out is to do it twice. + for (int j = 0; j < 2; j++) { + int i = 1; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { int width = ((int *)gap->ga_data)[i++]; int height = ((int *)gap->ga_data)[i++]; @@ -5329,6 +5349,8 @@ void win_setwidth_win(int width, win_T *wp) width = p_wmw; if (width == 0) width = 1; + } else if (width < 0) { + width = 0; } if (wp->w_floating) { wp->w_float_config.width = width; @@ -5856,10 +5878,10 @@ void scroll_to_fraction(win_T *wp, int prev_height) } if (wp == curwin) { - if (get_scrolloff_value()) { - update_topline(); + if (get_scrolloff_value(wp)) { + update_topline(wp); } - curs_columns(false); // validate w_wrow + curs_columns(wp, false); // validate w_wrow } if (prev_height > 0) { wp->w_prev_fraction_row = wp->w_wrow; @@ -5915,8 +5937,8 @@ void win_set_inner_size(win_T *wp) changed_line_abv_curs_win(wp); invalidate_botline_win(wp); if (wp == curwin) { - update_topline(); - curs_columns(true); // validate w_wrow + update_topline(wp); + curs_columns(wp, true); // validate w_wrow } redraw_later(wp, NOT_VALID); } |