From 53f5b3d70983bc1d86a5c45c943a6eafc9f55344 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 14 Jul 2017 12:42:43 +0900 Subject: [PATCH] Fix an assert in compute modified ranges when merging single char ranges Due to the way Selection::min/max worked, we were creating backward selections, with cursor < anchor, which was triggering an assert when trying to move cursor back one char when it was already on the first char of the buffer. --- src/selection.hh | 9 +++++---- test/regression/0-compute-modified-range-crash/cmd | 1 + test/regression/0-compute-modified-range-crash/in | 1 + test/regression/0-compute-modified-range-crash/out | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 test/regression/0-compute-modified-range-crash/cmd create mode 100644 test/regression/0-compute-modified-range-crash/in create mode 100644 test/regression/0-compute-modified-range-crash/out diff --git a/src/selection.hh b/src/selection.hh index 08451521..4b6269f3 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -44,11 +44,12 @@ struct Selection return m_anchor == other.m_anchor and m_cursor == other.m_cursor; } - const BufferCoord& min() const { return m_anchor < m_cursor ? m_anchor : m_cursor; } - const BufferCoord& max() const { return m_anchor < m_cursor ? m_cursor : m_anchor; } + // When selections are single char, we want the anchor to be considered min, and cursor max + const BufferCoord& min() const { return m_anchor <= m_cursor ? m_anchor : m_cursor; } + const BufferCoord& max() const { return m_anchor <= m_cursor ? m_cursor : m_anchor; } - BufferCoord& min() { return m_anchor < m_cursor ? m_anchor : m_cursor; } - BufferCoord& max() { return m_anchor < m_cursor ? m_cursor : m_anchor; } + BufferCoord& min() { return m_anchor <= m_cursor ? m_anchor : m_cursor; } + BufferCoord& max() { return m_anchor <= m_cursor ? m_cursor : m_anchor; } private: BufferCoord m_anchor; diff --git a/test/regression/0-compute-modified-range-crash/cmd b/test/regression/0-compute-modified-range-crash/cmd new file mode 100644 index 00000000..8e07dd1b --- /dev/null +++ b/test/regression/0-compute-modified-range-crash/cmd @@ -0,0 +1 @@ +es.!echou diff --git a/test/regression/0-compute-modified-range-crash/in b/test/regression/0-compute-modified-range-crash/in new file mode 100644 index 00000000..5c9e84ff --- /dev/null +++ b/test/regression/0-compute-modified-range-crash/in @@ -0,0 +1 @@ +aha diff --git a/test/regression/0-compute-modified-range-crash/out b/test/regression/0-compute-modified-range-crash/out new file mode 100644 index 00000000..5c9e84ff --- /dev/null +++ b/test/regression/0-compute-modified-range-crash/out @@ -0,0 +1 @@ +aha