1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-02 00:46:42 +03:00

Clamp m_anchor in mouse handler, nothing garantees that it is still valid

Fixes #350
This commit is contained in:
Maxime Coste 2015-08-14 13:12:44 +01:00
parent 5f115c90ff
commit 92d3178305

View File

@ -72,11 +72,12 @@ struct MouseHandler
if (not context.has_window()) if (not context.has_window())
return false; return false;
Buffer& buffer = context.buffer();
if (key.modifiers == Key::Modifiers::MousePress) if (key.modifiers == Key::Modifiers::MousePress)
{ {
m_dragging = true; m_dragging = true;
m_anchor = context.window().buffer_coord(key.mouse_coord()); m_anchor = context.window().buffer_coord(key.mouse_coord());
context.selections_write_only() = SelectionList{ context.buffer(), m_anchor }; context.selections_write_only() = SelectionList{ buffer, m_anchor };
return true; return true;
} }
if (key.modifiers == Key::Modifiers::MouseRelease) if (key.modifiers == Key::Modifiers::MouseRelease)
@ -85,7 +86,8 @@ struct MouseHandler
return true; return true;
m_dragging = false; m_dragging = false;
auto cursor = context.window().buffer_coord(key.mouse_coord()); auto cursor = context.window().buffer_coord(key.mouse_coord());
context.selections_write_only() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} }; context.selections_write_only() =
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
return true; return true;
} }
if (key.modifiers == Key::Modifiers::MousePos) if (key.modifiers == Key::Modifiers::MousePos)
@ -93,7 +95,8 @@ struct MouseHandler
if (not m_dragging) if (not m_dragging)
return true; return true;
auto cursor = context.window().buffer_coord(key.mouse_coord()); auto cursor = context.window().buffer_coord(key.mouse_coord());
context.selections_write_only() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} }; context.selections_write_only() =
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
return true; return true;
} }
if (key.modifiers == Key::Modifiers::MouseWheelDown) if (key.modifiers == Key::Modifiers::MouseWheelDown)