Fix crash when deleting a buffer from a user mapping

Deleting a buffer resets normal mode on all clients that were
displaing that buffer, but ScopedForceNormalMode that are used
from user mode  do not take this possiblity into account on
destruction, which leads to deleting the last normal mode from
the context, ending up with an empty mode stack.

Fixes #3909
This commit is contained in:
Maxime Coste 2022-04-12 12:49:19 +10:00
parent b2c6bc4690
commit 90db664635
6 changed files with 9 additions and 9 deletions

View File

@ -1698,15 +1698,10 @@ InputHandler::ScopedForceNormal::~ScopedForceNormal()
if (m_mode == m_handler.m_mode_stack.back().get()) if (m_mode == m_handler.m_mode_stack.back().get())
m_handler.pop_mode(m_mode); m_handler.pop_mode(m_mode);
else else if (auto it = find(m_handler.m_mode_stack, m_mode);
{ it != m_handler.m_mode_stack.end())
auto it = find_if(m_handler.m_mode_stack,
[this](const RefPtr<InputMode>& m)
{ return m.get() == m_mode; });
kak_assert(it != m_handler.m_mode_stack.end());
m_handler.m_mode_stack.erase(it); m_handler.m_mode_stack.erase(it);
} }
}
static bool is_valid(Key key) static bool is_valid(Key key)
{ {

View File

@ -88,8 +88,8 @@ struct RefPtr
acquire(); acquire();
} }
friend bool operator==(const RefPtr& lhs, const RefPtr& rhs) { return lhs.m_ptr == rhs.m_ptr; } friend bool operator==(const RefPtr& lhs, const RefPtr& rhs) = default;
friend bool operator!=(const RefPtr& lhs, const RefPtr& rhs) { return lhs.m_ptr != rhs.m_ptr; } friend bool operator==(const RefPtr& lhs, const T* rhs) { return lhs.m_ptr == rhs; }
private: private:
T* m_ptr = nullptr; T* m_ptr = nullptr;

View File

@ -0,0 +1 @@
i<a-;>,d<esc>

View File

@ -0,0 +1,2 @@
edit -scratch
map global user d :delete-buffer<ret>