diff options
Diffstat (limited to 'src/nvim/window.c')
| -rw-r--r-- | src/nvim/window.c | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index fd6755a382..90c8ba92f9 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -139,6 +139,32 @@ win_T *prevwin_curwin(void) return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin; } +/// If the 'switchbuf' option contains "useopen" or "usetab", then try to jump +/// to a window containing "buf". +/// Returns the pointer to the window that was jumped to or NULL. +win_T *swbuf_goto_win_with_buf(buf_T *buf) +{ + win_T *wp = NULL; + + if (buf == NULL) { + return wp; + } + + // If 'switchbuf' contains "useopen": jump to first window in the current + // tab page containing "buf" if one exists. + if (swb_flags & SWB_USEOPEN) { + wp = buf_jump_open_win(buf); + } + + // If 'switchbuf' contains "usetab": jump to first window in any tab page + // containing "buf" if one exists. + if (wp == NULL && (swb_flags & SWB_USETAB)) { + wp = buf_jump_open_tab(buf); + } + + return wp; +} + /// all CTRL-W window commands are handled here, called from normal_cmd(). /// /// @param xchar extra char from ":wincmd gx" or NUL @@ -514,18 +540,31 @@ wingotofile: tabpage_T *oldtab = curtab; win_T *oldwin = curwin; setpcmark(); - if (win_split(0, 0) == OK) { + + // If 'switchbuf' is set to 'useopen' or 'usetab' and the + // file is already opened in a window, then jump to it. + win_T *wp = NULL; + if ((swb_flags & (SWB_USEOPEN | SWB_USETAB)) + && cmdmod.cmod_tab == 0) { + wp = swbuf_goto_win_with_buf(buflist_findname_exp(ptr)); + } + + if (wp == NULL && win_split(0, 0) == OK) { RESET_BINDING(curwin); if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) { // Failed to open the file, close the window opened for it. win_close(curwin, false, false); goto_tabpage_win(oldtab, oldwin); - } else if (nchar == 'F' && lnum >= 0) { - curwin->w_cursor.lnum = lnum; - check_cursor_lnum(); - beginline(BL_SOL | BL_FIX); + } else { + wp = curwin; } } + + if (wp != NULL && nchar == 'F' && lnum >= 0) { + curwin->w_cursor.lnum = lnum; + check_cursor_lnum(); + beginline(BL_SOL | BL_FIX); + } xfree(ptr); } break; @@ -2278,6 +2317,9 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int } if (hnc) { // add next_curwin size next_curwin_size -= (int)p_wiw - (m - n); + if (next_curwin_size < 0) { + next_curwin_size = 0; + } new_size += next_curwin_size; room -= new_size - next_curwin_size; } else { @@ -4035,7 +4077,7 @@ static tabpage_T *alloc_tabpage(void) static int last_tp_handle = 0; tabpage_T *tp = xcalloc(1, sizeof(tabpage_T)); tp->handle = ++last_tp_handle; - pmap_put(handle_T)(&tabpage_handles, tp->handle, tp); + pmap_put(int)(&tabpage_handles, tp->handle, tp); // Init t: variables. tp->tp_vars = tv_dict_alloc(); @@ -4048,7 +4090,7 @@ static tabpage_T *alloc_tabpage(void) void free_tabpage(tabpage_T *tp) { - pmap_del(handle_T)(&tabpage_handles, tp->handle); + pmap_del(int)(&tabpage_handles, tp->handle, NULL); diff_clear(tp); for (int idx = 0; idx < SNAP_COUNT; idx++) { clear_snapshot(tp, idx); @@ -5020,7 +5062,7 @@ static win_T *win_alloc(win_T *after, bool hidden) win_T *new_wp = xcalloc(1, sizeof(win_T)); new_wp->handle = ++last_win_id; - pmap_put(handle_T)(&window_handles, new_wp->handle, new_wp); + pmap_put(int)(&window_handles, new_wp->handle, new_wp); grid_assign_handle(&new_wp->w_grid_alloc); @@ -5082,7 +5124,7 @@ void free_wininfo(wininfo_T *wip, buf_T *bp) /// @param tp tab page "win" is in, NULL for current static void win_free(win_T *wp, tabpage_T *tp) { - pmap_del(handle_T)(&window_handles, wp->handle); + pmap_del(int)(&window_handles, wp->handle, NULL); clearFolding(wp); // reduce the reference count to the argument list. @@ -6660,7 +6702,8 @@ static int win_border_width(win_T *wp) /// Set the width of a window. void win_new_width(win_T *wp, int width) { - wp->w_width = width; + // Should we give an error if width < 0? + wp->w_width = width < 0 ? 0 : width; wp->w_pos_changed = true; win_set_inner_size(wp, true); } |
