From 92d3178305f178e6ccc605482bb57d3e9169e7c5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 14 Aug 2015 13:12:44 +0100 Subject: [PATCH] Clamp m_anchor in mouse handler, nothing garantees that it is still valid Fixes #350 --- src/input_handler.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 2ab3f98c..cefe65b1 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -72,11 +72,12 @@ struct MouseHandler if (not context.has_window()) return false; + Buffer& buffer = context.buffer(); if (key.modifiers == Key::Modifiers::MousePress) { m_dragging = true; 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; } if (key.modifiers == Key::Modifiers::MouseRelease) @@ -85,7 +86,8 @@ struct MouseHandler return true; m_dragging = false; 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; } if (key.modifiers == Key::Modifiers::MousePos) @@ -93,7 +95,8 @@ struct MouseHandler if (not m_dragging) return true; 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; } if (key.modifiers == Key::Modifiers::MouseWheelDown)