forked from aniani/vim
patch 9.0.0907: restoring window after WinScrolled may fail
Problem: Restoring window after WinScrolled may fail. Solution: Lock the window layout when triggering WinScrolled.
This commit is contained in:
@@ -3341,3 +3341,5 @@ EXTERN char e_cannot_change_menus_while_listing[]
|
|||||||
#endif
|
#endif
|
||||||
EXTERN char e_cannot_change_user_commands_while_listing[]
|
EXTERN char e_cannot_change_user_commands_while_listing[]
|
||||||
INIT(= N_("E1311: Cannot change user commands while listing"));
|
INIT(= N_("E1311: Cannot change user commands while listing"));
|
||||||
|
EXTERN char e_not_allowed_to_change_window_layout_in_this_autocmd[]
|
||||||
|
INIT(= N_("E1312: Not allowed to change the window layout in this autocmd"));
|
||||||
|
@@ -6055,6 +6055,8 @@ ex_win_close(
|
|||||||
emsg(_(e_cannot_close_autocmd_or_popup_window));
|
emsg(_(e_cannot_close_autocmd_or_popup_window));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (window_layout_locked())
|
||||||
|
return;
|
||||||
|
|
||||||
need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
|
need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
|
||||||
if (need_hide && !buf_hide(buf) && !forceit)
|
if (need_hide && !buf_hide(buf) && !forceit)
|
||||||
@@ -6227,7 +6229,7 @@ ex_tabclose(exarg_T *eap)
|
|||||||
cmdwin_result = K_IGNORE;
|
cmdwin_result = K_IGNORE;
|
||||||
else if (first_tabpage->tp_next == NULL)
|
else if (first_tabpage->tp_next == NULL)
|
||||||
emsg(_(e_cannot_close_last_tab_page));
|
emsg(_(e_cannot_close_last_tab_page));
|
||||||
else
|
else if (!window_layout_locked())
|
||||||
{
|
{
|
||||||
tab_number = get_tabpage_arg(eap);
|
tab_number = get_tabpage_arg(eap);
|
||||||
if (eap->errmsg == NULL)
|
if (eap->errmsg == NULL)
|
||||||
@@ -6263,7 +6265,7 @@ ex_tabonly(exarg_T *eap)
|
|||||||
cmdwin_result = K_IGNORE;
|
cmdwin_result = K_IGNORE;
|
||||||
else if (first_tabpage->tp_next == NULL)
|
else if (first_tabpage->tp_next == NULL)
|
||||||
msg(_("Already only one tab page"));
|
msg(_("Already only one tab page"));
|
||||||
else
|
else if (!window_layout_locked())
|
||||||
{
|
{
|
||||||
tab_number = get_tabpage_arg(eap);
|
tab_number = get_tabpage_arg(eap);
|
||||||
if (eap->errmsg == NULL)
|
if (eap->errmsg == NULL)
|
||||||
@@ -6296,6 +6298,9 @@ ex_tabonly(exarg_T *eap)
|
|||||||
void
|
void
|
||||||
tabpage_close(int forceit)
|
tabpage_close(int forceit)
|
||||||
{
|
{
|
||||||
|
if (window_layout_locked())
|
||||||
|
return;
|
||||||
|
|
||||||
// First close all the windows but the current one. If that worked then
|
// First close all the windows but the current one. If that worked then
|
||||||
// close the last window in this tab, that will close it.
|
// close the last window in this tab, that will close it.
|
||||||
if (!ONE_WINDOW)
|
if (!ONE_WINDOW)
|
||||||
@@ -6341,14 +6346,15 @@ tabpage_close_other(tabpage_T *tp, int forceit)
|
|||||||
static void
|
static void
|
||||||
ex_only(exarg_T *eap)
|
ex_only(exarg_T *eap)
|
||||||
{
|
{
|
||||||
win_T *wp;
|
if (window_layout_locked())
|
||||||
int wnr;
|
return;
|
||||||
# ifdef FEAT_GUI
|
# ifdef FEAT_GUI
|
||||||
need_mouse_correct = TRUE;
|
need_mouse_correct = TRUE;
|
||||||
# endif
|
# endif
|
||||||
if (eap->addr_count > 0)
|
if (eap->addr_count > 0)
|
||||||
{
|
{
|
||||||
wnr = eap->line2;
|
win_T *wp;
|
||||||
|
int wnr = eap->line2;
|
||||||
for (wp = firstwin; --wnr > 0; )
|
for (wp = firstwin; --wnr > 0; )
|
||||||
{
|
{
|
||||||
if (wp->w_next == NULL)
|
if (wp->w_next == NULL)
|
||||||
@@ -6367,6 +6373,8 @@ ex_hide(exarg_T *eap UNUSED)
|
|||||||
// ":hide" or ":hide | cmd": hide current window
|
// ":hide" or ":hide | cmd": hide current window
|
||||||
if (!eap->skip)
|
if (!eap->skip)
|
||||||
{
|
{
|
||||||
|
if (window_layout_locked())
|
||||||
|
return;
|
||||||
#ifdef FEAT_GUI
|
#ifdef FEAT_GUI
|
||||||
need_mouse_correct = TRUE;
|
need_mouse_correct = TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
/* window.c */
|
/* window.c */
|
||||||
|
int window_layout_locked(void);
|
||||||
win_T *prevwin_curwin(void);
|
win_T *prevwin_curwin(void);
|
||||||
void do_window(int nchar, long Prenum, int xchar);
|
void do_window(int nchar, long Prenum, int xchar);
|
||||||
void get_wincmd_addr_type(char_u *arg, exarg_T *eap);
|
void get_wincmd_addr_type(char_u *arg, exarg_T *eap);
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
907,
|
||||||
/**/
|
/**/
|
||||||
906,
|
906,
|
||||||
/**/
|
/**/
|
||||||
|
56
src/window.c
56
src/window.c
@@ -84,6 +84,48 @@ static char *m_onlyone = N_("Already only one window");
|
|||||||
// autocommands mess up the window structure.
|
// autocommands mess up the window structure.
|
||||||
static int split_disallowed = 0;
|
static int split_disallowed = 0;
|
||||||
|
|
||||||
|
// When non-zero closing a window is forbidden. Used to avoid that nasty
|
||||||
|
// autocommands mess up the window structure.
|
||||||
|
static int close_disallowed = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disallow changing the window layout (split window, close window, move
|
||||||
|
* window). Resizing is still allowed.
|
||||||
|
* Used for autocommands that temporarily use another window and need to
|
||||||
|
* make sure the previously selected window is still there.
|
||||||
|
* Must be matched with exactly one call to window_layout_unlock()!
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
window_layout_lock(void)
|
||||||
|
{
|
||||||
|
++split_disallowed;
|
||||||
|
++close_disallowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_layout_unlock(void)
|
||||||
|
{
|
||||||
|
--split_disallowed;
|
||||||
|
--close_disallowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When the window layout cannot be changed give an error and return TRUE.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
window_layout_locked(void)
|
||||||
|
{
|
||||||
|
if (split_disallowed > 0 || close_disallowed > 0)
|
||||||
|
{
|
||||||
|
if (close_disallowed == 0)
|
||||||
|
emsg(_(e_cannot_split_window_when_closing_buffer));
|
||||||
|
else
|
||||||
|
emsg(_(e_not_allowed_to_change_window_layout_in_this_autocmd));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// #define WIN_DEBUG
|
// #define WIN_DEBUG
|
||||||
#ifdef WIN_DEBUG
|
#ifdef WIN_DEBUG
|
||||||
/*
|
/*
|
||||||
@@ -2531,6 +2573,8 @@ win_close(win_T *win, int free_buf)
|
|||||||
emsg(_(e_cannot_close_last_window));
|
emsg(_(e_cannot_close_last_window));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
if (window_layout_locked())
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
if (win->w_closing || (win->w_buffer != NULL
|
if (win->w_closing || (win->w_buffer != NULL
|
||||||
&& win->w_buffer->b_locked > 0))
|
&& win->w_buffer->b_locked > 0))
|
||||||
@@ -2802,24 +2846,28 @@ trigger_winclosed(win_T *win)
|
|||||||
void
|
void
|
||||||
may_trigger_winscrolled(void)
|
may_trigger_winscrolled(void)
|
||||||
{
|
{
|
||||||
win_T *wp = curwin;
|
|
||||||
static int recursive = FALSE;
|
static int recursive = FALSE;
|
||||||
char_u winid[NUMBUFLEN];
|
|
||||||
|
|
||||||
if (recursive || !has_winscrolled())
|
if (recursive || !has_winscrolled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
win_T *wp = curwin;
|
||||||
if (wp->w_last_topline != wp->w_topline
|
if (wp->w_last_topline != wp->w_topline
|
||||||
|| wp->w_last_leftcol != wp->w_leftcol
|
|| wp->w_last_leftcol != wp->w_leftcol
|
||||||
|| wp->w_last_skipcol != wp->w_skipcol
|
|| wp->w_last_skipcol != wp->w_skipcol
|
||||||
|| wp->w_last_width != wp->w_width
|
|| wp->w_last_width != wp->w_width
|
||||||
|| wp->w_last_height != wp->w_height)
|
|| wp->w_last_height != wp->w_height)
|
||||||
{
|
{
|
||||||
vim_snprintf((char *)winid, sizeof(winid), "%d", wp->w_id);
|
// "curwin" may be different from the actual current window, make sure
|
||||||
|
// it can be restored.
|
||||||
|
window_layout_lock();
|
||||||
|
|
||||||
recursive = TRUE;
|
recursive = TRUE;
|
||||||
|
char_u winid[NUMBUFLEN];
|
||||||
|
vim_snprintf((char *)winid, sizeof(winid), "%d", wp->w_id);
|
||||||
apply_autocmds(EVENT_WINSCROLLED, winid, winid, FALSE, wp->w_buffer);
|
apply_autocmds(EVENT_WINSCROLLED, winid, winid, FALSE, wp->w_buffer);
|
||||||
recursive = FALSE;
|
recursive = FALSE;
|
||||||
|
window_layout_unlock();
|
||||||
|
|
||||||
// an autocmd may close the window, "wp" may be invalid now
|
// an autocmd may close the window, "wp" may be invalid now
|
||||||
if (win_valid_any_tab(wp))
|
if (win_valid_any_tab(wp))
|
||||||
@@ -4014,6 +4062,8 @@ win_new_tabpage(int after)
|
|||||||
emsg(_(e_invalid_in_cmdline_window));
|
emsg(_(e_invalid_in_cmdline_window));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
if (window_layout_locked())
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
newtp = alloc_tabpage();
|
newtp = alloc_tabpage();
|
||||||
if (newtp == NULL)
|
if (newtp == NULL)
|
||||||
|
Reference in New Issue
Block a user