]> granicus.if.org Git - vim/commitdiff
patch 8.2.0984: not using previous window when closing a shell popup window v8.2.0984
authorBram Moolenaar <Bram@vim.org>
Mon, 15 Jun 2020 19:19:08 +0000 (21:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 15 Jun 2020 19:19:08 +0000 (21:19 +0200)
Problem:    Not using previous window when closing a shell popup window.
Solution:   Use "prevwin" if it was set. (closes #6267)

src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index fbda48bf749cde88994f76908cad045e014b3c4d..d144be73fe1c22c39da001a0741f76aa34d8fc3c 100644 (file)
@@ -2147,6 +2147,19 @@ invoke_popup_callback(win_T *wp, typval_T *result)
     clear_tv(&rettv);
 }
 
+/*
+ * Make "prevwin" the current window, unless it's equal to "wp".
+ * Otherwise make "firstwin" the current window.
+ */
+    static void
+back_to_prevwin(win_T *wp)
+{
+    if (win_valid(prevwin) && wp != prevwin)
+       win_enter(prevwin, FALSE);
+    else
+       win_enter(firstwin, FALSE);
+}
+
 /*
  * Close popup "wp" and invoke any close callback for it.
  */
@@ -2178,10 +2191,8 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
                    break;
            if (owp != NULL)
                win_enter(owp, FALSE);
-           else if (win_valid(prevwin) && wp != prevwin)
-               win_enter(prevwin, FALSE);
            else
-               win_enter(firstwin, FALSE);
+               back_to_prevwin(wp);
        }
     }
 #endif
@@ -2583,7 +2594,7 @@ popup_close(int id, int force)
                    error_for_popup_window();
                    return FAIL;
                }
-               win_enter(firstwin, FALSE);
+               back_to_prevwin(wp);
            }
            if (prev == NULL)
                first_popupwin = wp->w_next;
@@ -2620,7 +2631,7 @@ popup_close_tabpage(tabpage_T *tp, int id, int force)
                    error_for_popup_window();
                    return FAIL;
                }
-               win_enter(firstwin, FALSE);
+               back_to_prevwin(wp);
            }
            if (prev == NULL)
                *root = wp->w_next;
index 1e7d5eed105c6c84f7912288d66450e7e7efbfe7..2188c2c6a9262fd4d25c5bde97bf4c3e4cbfa0d9 100644 (file)
@@ -2461,6 +2461,23 @@ func Test_popupwin_terminal_buffer()
   call assert_equal(origwin, win_getid())
 endfunc
 
+func Test_popupwin_close_prevwin()
+  CheckFeature terminal
+
+  call assert_equal(1, winnr('$'))
+  split
+  wincmd b
+  call assert_equal(2, winnr())
+  let buf = term_start(&shell, #{hidden: 1})
+  call popup_create(buf, {})
+  call term_wait(buf, 100)
+  call popup_clear(1)
+  call assert_equal(2, winnr())
+
+  quit
+  exe 'bwipe! ' .. buf
+endfunc
+
 func Test_popupwin_with_buffer_and_filter()
   new Xwithfilter
   call setline(1, range(100))
index 7d7b965f031fff6a209225cd9bd37e05c0a92b34..91ae5ea1a59d7bb9f700c354c6db700546e75f2e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    984,
 /**/
     983,
 /**/