Skip to content

Commit

Permalink
Discard resize if already resizing for same size
Browse files Browse the repository at this point in the history
When resizeNeovim() is called we can defer the call for later, but we
should never defer a resize if the target size is the same. Otherwise
we can end up in a loop with Neovim issuing resize events.
  • Loading branch information
equalsraf committed Feb 5, 2024
1 parent f5c95b1 commit a7fe81e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/gui/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,11 +1608,22 @@ void Shell::resizeNeovim(int n_cols, int n_rows)
if (!m_nvim || (n_cols == columns() && n_rows == rows())) {
return;
}
if (m_resizing) {
m_resize_neovim_pending = QSize(n_cols, n_rows);
} else {

auto newsize = QSize(n_cols, n_rows);

if (m_resizing.isValid() && m_resizing == newsize) {
// Do not trigger two consecutive resizes for the same size.
// Neovim may fail to resize and issue a resize event that
// would result in a loop
return;
}

if (m_resizing.isValid()) {
m_resize_neovim_pending = newsize;
}
else {
m_nvim->api0()->ui_try_resize(n_cols, n_rows);
m_resizing = true;
m_resizing = newsize;
}
}

Expand All @@ -1632,7 +1643,8 @@ void Shell::resizeEvent(QResizeEvent *ev)
*/
void Shell::neovimResizeFinished()
{
m_resizing = false;
m_resizing = QSize();

if (m_resize_neovim_pending.isValid()) {
resizeNeovim(m_resize_neovim_pending.width(),
m_resize_neovim_pending.height());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private slots:
/// Neovim mode descriptions from "mode_change", used by guicursor
QVariantList m_modeInfo;

bool m_resizing{ false };
QSize m_resizing;
QSize m_resize_neovim_pending;
QLabel* m_tooltip{ nullptr };
QPoint m_mouse_pos;
Expand Down

0 comments on commit a7fe81e

Please sign in to comment.