# HG changeset patch # User Bram Moolenaar # Date 1558872906 -7200 # Node ID ddfa924df50deef254862da5f8438ff590b2c8bd # Parent c7a0f8ed435de5a6b0bc0b6c3d596fcd9fd28daa patch 8.1.1399: popup windows not adjusted when switching tabs commit https://github.com/vim/vim/commit/ec58384afa0dc1678afd7b8d19b4645ac2f73f42 Author: Bram Moolenaar Date: Sun May 26 14:11:23 2019 +0200 patch 8.1.1399: popup windows not adjusted when switching tabs Problem: Popup windows not adjusted when switching tabs. Solution: Save and restore first_tab_popupwin. Fix closing a tabpage. diff --git a/src/popupwin.c b/src/popupwin.c --- a/src/popupwin.c +++ b/src/popupwin.c @@ -177,40 +177,59 @@ f_popup_close(typval_T *argvars, typval_ popup_close(nr); } +/* + * Close a popup window by Window-id. + */ void -popup_close(int nr) +popup_close(int id) { win_T *wp; + tabpage_T *tp; win_T *prev = NULL; + // go through global popups for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next) - if (wp->w_id == nr) + if (wp->w_id == id) { if (prev == NULL) first_popupwin = wp->w_next; else prev->w_next = wp->w_next; - break; + win_free_popup(wp); + redraw_all_later(NOT_VALID); + return; } - if (wp == NULL) - { - prev = NULL; - for (wp = first_tab_popupwin; wp != NULL; prev = wp, wp = wp->w_next) - if (wp->w_id == nr) - { - if (prev == NULL) - first_tab_popupwin = wp->w_next; - else - prev->w_next = wp->w_next; - break; - } - } - if (wp != NULL) - { - win_free_popup(wp); - redraw_all_later(NOT_VALID); - } + // go through tab-local popups + FOR_ALL_TABPAGES(tp) + popup_close_tabpage(tp, id); +} + +/* + * Close a popup window with Window-id "id" in tabpage "tp". + */ + void +popup_close_tabpage(tabpage_T *tp, int id) +{ + win_T *wp; + win_T **root; + win_T *prev = NULL; + + if (tp == curtab) + root = &first_tab_popupwin; + else + root = &tp->tp_first_popupwin; + for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next) + if (wp->w_id == id) + { + if (prev == NULL) + *root = wp->w_next; + else + prev->w_next = wp->w_next; + win_free_popup(wp); + redraw_all_later(NOT_VALID); + return; + } } void diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro --- a/src/proto/popupwin.pro +++ b/src/proto/popupwin.pro @@ -1,7 +1,8 @@ /* popupwin.c */ void f_popup_create(typval_T *argvars, typval_T *rettv); void f_popup_close(typval_T *argvars, typval_T *rettv); -void popup_close(int nr); +void popup_close(int id); +void popup_close_tabpage(tabpage_T *tp, int id); void close_all_popups(void); void ex_popupclear(exarg_T *eap); /* vim: set ft=c : */ diff --git a/src/testdir/dumps/Test_popupwin_02.dump b/src/testdir/dumps/Test_popupwin_02.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_02.dump @@ -0,0 +1,10 @@ +| +8#0000001#e0e0e08|+| |[|N|o| |N|a|m|e|]| | +2#0000000#ffffff0|[|N|o| |N|a|m|e|]| | +1&&@49|X+8#0000001#e0e0e08 +> +0#0000000#ffffff0@74 +|~+0#4040ff13&| @73 +|~| @6|o+0#0000001#ffd7ff255|t|h|e|r| |t|a|b| @10| +0#4040ff13#ffffff0@46 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|:+0#0000000&|c|a|l@1| |p|o|p|u|p|_|c|r|e|a|t|e|(|'|o|t|h|e|r| |t|a|b|'|,| |{|'|l|i|n|e|'|:| |4|,| |'|c|o|l|'|:| |9|}|)| @2|0|,|0|-|1| @8|A|l@1| diff --git a/src/testdir/dumps/Test_popupwin_03.dump b/src/testdir/dumps/Test_popupwin_03.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_03.dump @@ -0,0 +1,10 @@ +| +2&#ffffff0|+| |[|N|o| |N|a|m|e|]| | +8#0000001#e0e0e08|[|N|o| |N|a|m|e|]| | +1#0000000#ffffff0@49|X+8#0000001#e0e0e08 +>1+0#0000000#ffffff0| @73 +|2| @8|h+0fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0#0000001#ffd7ff255| |o|n|e| @8| +0#0000000#ffffff0@30 +|3| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|w|o| @8| +0#0000000#ffffff0@30 +|4| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0#0000000#ffffff0@30 +|5| @73 +|6| @73 +|7| @73 +|8| @73 +|:|c|a|l@1| |p|o|p|u|p|_|c|r|e|a|t|e|(|'|o|t|h|e|r| |t|a|b|'|,| |{|'|l|i|n|e|'|:| |4|,| |'|c|o| @9|1|,|1| @10|T|o|p| diff --git a/src/testdir/dumps/Test_popupwin_04.dump b/src/testdir/dumps/Test_popupwin_04.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_04.dump @@ -0,0 +1,10 @@ +> +0&#ffffff0@74 +|~+0#4040ff13&| @73 +|~| @73 +|~| @6|o+0#0000001#ffd7ff255|t|h|e|r| |t|a|b| @10| +0#4040ff13#ffffff0@46 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|:+0#0000000&|q|u|i|t|!| @50|0|,|0|-|1| @8|A|l@1| diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -20,6 +20,19 @@ func Test_simple_popup() let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) call VerifyScreenDump(buf, 'Test_popupwin_01', {}) + " Add a tabpage + call term_sendkeys(buf, ":tabnew\") + call term_sendkeys(buf, ":call popup_create('other tab', {'line': 4, 'col': 9})\") + call VerifyScreenDump(buf, 'Test_popupwin_02', {}) + + " switch back to first tabpage + call term_sendkeys(buf, "gt") + call VerifyScreenDump(buf, 'Test_popupwin_03', {}) + + " close that tabpage + call term_sendkeys(buf, ":quit!\") + call VerifyScreenDump(buf, 'Test_popupwin_04', {}) + " clean up call StopVimInTerminal(buf) call delete('XtestPopup') diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -768,6 +768,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1399, +/**/ 1398, /**/ 1397, diff --git a/src/window.c b/src/window.c --- a/src/window.c +++ b/src/window.c @@ -3670,8 +3670,17 @@ free_tabpage(tabpage_T *tp) diff_clear(tp); # endif # ifdef FEAT_TEXT_PROP - while (tp->tp_first_popupwin != NULL) - popup_close(tp->tp_first_popupwin->w_id); + { + win_T *wp; + + for (;;) + { + wp = tp == curtab ? first_tab_popupwin : tp->tp_first_popupwin; + if (wp == NULL) + break; + popup_close_tabpage(tp, wp->w_id); + } + } #endif for (idx = 0; idx < SNAP_COUNT; ++idx) clear_snapshot(tp, idx); @@ -3964,6 +3973,10 @@ leave_tabpage( tp->tp_prevwin = prevwin; tp->tp_firstwin = firstwin; tp->tp_lastwin = lastwin; +#ifdef FEAT_TEXT_PROP + tp->tp_first_popupwin = first_tab_popupwin; + first_tab_popupwin = NULL; +#endif tp->tp_old_Rows = Rows; tp->tp_old_Columns = Columns; firstwin = NULL; @@ -3991,6 +4004,9 @@ enter_tabpage( firstwin = tp->tp_firstwin; lastwin = tp->tp_lastwin; topframe = tp->tp_topframe; +#ifdef FEAT_TEXT_PROP + first_tab_popupwin = tp->tp_first_popupwin; +#endif /* We would like doing the TabEnter event first, but we don't have a * valid current window yet, which may break some commands. @@ -6497,9 +6513,15 @@ switch_win( { curtab->tp_firstwin = firstwin; curtab->tp_lastwin = lastwin; +#ifdef FEAT_TEXT_PROP + curtab->tp_first_popupwin = first_tab_popupwin ; +#endif curtab = tp; firstwin = curtab->tp_firstwin; lastwin = curtab->tp_lastwin; +#ifdef FEAT_TEXT_PROP + first_tab_popupwin = curtab->tp_first_popupwin; +#endif } else goto_tabpage_tp(tp, FALSE, FALSE); @@ -6528,9 +6550,15 @@ restore_win( { curtab->tp_firstwin = firstwin; curtab->tp_lastwin = lastwin; +#ifdef FEAT_TEXT_PROP + curtab->tp_first_popupwin = first_tab_popupwin ; +#endif curtab = save_curtab; firstwin = curtab->tp_firstwin; lastwin = curtab->tp_lastwin; +#ifdef FEAT_TEXT_PROP + first_tab_popupwin = curtab->tp_first_popupwin; +#endif } else goto_tabpage_tp(save_curtab, FALSE, FALSE);