Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/quickfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4612,6 +4612,12 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
if (cmdmod.cmod_split == 0)
flags = WSP_BELOW;
flags |= WSP_NEWLOC;

// Create a snapshot for quickfix window (not for location list)
// so that when closing it, we can restore to the previous window
if (IS_QF_STACK(qi))
flags |= WSP_QUICKFIX;

if (win_split(height, flags) == FAIL)
return FAIL; // not enough room for window
RESET_BINDING(curwin);
Expand Down
7 changes: 4 additions & 3 deletions src/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3693,9 +3693,10 @@ typedef void diffline_T;
typedef void diffline_change_T;
#endif

#define SNAP_HELP_IDX 0
#define SNAP_AUCMD_IDX 1
#define SNAP_COUNT 2
#define SNAP_HELP_IDX 0
#define SNAP_AUCMD_IDX 1
#define SNAP_QUICKFIX_IDX 2
#define SNAP_COUNT 3

/*
* Tab pages point to the top frame of each tab page.
Expand Down
11 changes: 11 additions & 0 deletions src/testdir/test_quickfix.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6958,4 +6958,15 @@ func Test_vimgrep_dummy_buffer_keep()
%bw!
endfunc

func Test_quickfix_restore_current_win()
let curwin = win_getid()
vsplit Xb
wincmd p
botright copen
cclose

call assert_equal(curwin, win_getid())
bw! Xb
endfunc

" vim: shiftwidth=2 sts=2 expandtab
1 change: 1 addition & 0 deletions src/vim.h
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define WSP_ABOVE 0x80 // put new window above/left
#define WSP_NEWLOC 0x100 // don't copy location list
#define WSP_FORCE_ROOM 0x200 // ignore "not enough room" errors
#define WSP_QUICKFIX 0x400 // creating the quickfix window

/*
* arguments for gui_set_shellsize()
Expand Down
24 changes: 18 additions & 6 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ win_split(int size, int flags)
else
clear_snapshot(curtab, SNAP_HELP_IDX);

if (flags & WSP_QUICKFIX)
make_snapshot(SNAP_QUICKFIX_IDX);
else
clear_snapshot(curtab, SNAP_QUICKFIX_IDX);

return win_split_ins(size, flags, NULL, 0, NULL);
}

Expand Down Expand Up @@ -2688,6 +2693,7 @@ win_close(win_T *win, int free_buf)
int close_curwin = FALSE;
int dir;
int help_window = FALSE;
int quickfix_window = FALSE;
tabpage_T *prev_curtab = curtab;
frame_T *win_frame = win->w_frame->fr_parent;
#ifdef FEAT_DIFF
Expand Down Expand Up @@ -2740,6 +2746,11 @@ win_close(win_T *win, int free_buf)
else
clear_snapshot(curtab, SNAP_HELP_IDX);

if (bt_quickfix(win->w_buffer))
quickfix_window = TRUE;
else
clear_snapshot(curtab, SNAP_QUICKFIX_IDX);

if (win == curwin)
{
#ifdef FEAT_JOB_CHANNEL
Expand Down Expand Up @@ -2845,11 +2856,11 @@ win_close(win_T *win, int free_buf)
// the screen space.
wp = win_free_mem(win, &dir, NULL);

if (help_window)
if (help_window || quickfix_window)
{
// Closing the help window moves the cursor back to the current window
// of the snapshot.
win_T *prev_win = get_snapshot_curwin(SNAP_HELP_IDX);
win_T *prev_win = get_snapshot_curwin(help_window ? SNAP_HELP_IDX : SNAP_QUICKFIX_IDX);

if (win_valid(prev_win))
wp = prev_win;
Expand Down Expand Up @@ -2939,10 +2950,11 @@ win_close(win_T *win, int free_buf)
--dont_parse_messages;
#endif

// After closing the help window, try restoring the window layout from
// before it was opened.
if (help_window)
restore_snapshot(SNAP_HELP_IDX, close_curwin);
// After closing the help or quickfix window, try restoring the window
// layout from before it was opened.
if (help_window || quickfix_window)
restore_snapshot(help_window ? SNAP_HELP_IDX : SNAP_QUICKFIX_IDX,
close_curwin);

#ifdef FEAT_DIFF
// If the window had 'diff' set and now there is only one window left in
Expand Down
Loading