From 7a7f86a205f5fbc74ad16967c1c24cf3aa46aab1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 22 Mar 2015 10:07:26 +0000 Subject: [PATCH] Impreove Window::buffer_coord behaviour with invalid coords --- src/window.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/window.cc b/src/window.cc index aa9f2824..b23fcdd8 100644 --- a/src/window.cc +++ b/src/window.cc @@ -249,9 +249,13 @@ CharCoord Window::display_position(ByteCoord coord) const ByteCoord Window::buffer_coord(CharCoord coord) const { - if (0_line <= coord.line and coord.line < m_display_buffer.lines().size()) - return find_buffer_coord(m_display_buffer.lines()[(int)coord.line], buffer(), coord.column); - return { 0, 0 }; + if (coord <= 0_line) + coord = {0,0}; + if ((int)coord.line >= m_display_buffer.lines().size()) + coord = CharCoord{(int)m_display_buffer.lines().size()-1, INT_MAX}; + + return find_buffer_coord(m_display_buffer.lines()[(int)coord.line], + buffer(), coord.column); } ByteCoord Window::offset_coord(ByteCoord coord, CharCount offset)