From 08509cb4087d7d79868fcff96080bb9947ce4e7b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 17 May 2020 14:04:59 +0200 Subject: [PATCH 1/2] Refactor: use is_eol() as elsewhere in this function --- src/selectors.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/selectors.cc b/src/selectors.cc index a64380406..baa2d9ac8 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -560,11 +560,11 @@ select_paragraph(const Context& context, const Selection& selection, BufferIterator first = buffer.iterator_at(selection.cursor()); if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and - *(first-1) == '\n' and *(first-2) == '\n') + is_eol(*(first-1)) and is_eol(*(first-2))) --first; else if ((flags & ObjectFlags::ToEnd) and first != buffer.begin() and (first+1) != buffer.end() and - *(first-1) == '\n' and *first == '\n') + is_eol(*(first-1)) and is_eol(*first)) ++first; BufferIterator last = first; From fc63eef69556637433b1351d0e8d2c4638883122 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 17 May 2020 13:55:54 +0200 Subject: [PATCH 2/2] Fix crash when selecting previous paragraph at buffer begin Fixes #3489 When there are multiple empty lines between a paragraph and the cursor (C in the example below), p skips over one of them. Prevent the check for the extra newline from going out of bounds. ``` a paragraph C after p, the first two lines will be selected ``` --- src/selectors.cc | 2 +- test/regression/3489-crash-on-paragraph-begin/cmd | 1 + test/regression/3489-crash-on-paragraph-begin/in | 2 ++ .../regression/3489-crash-on-paragraph-begin/kak_selection_desc | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/regression/3489-crash-on-paragraph-begin/cmd create mode 100644 test/regression/3489-crash-on-paragraph-begin/in create mode 100644 test/regression/3489-crash-on-paragraph-begin/kak_selection_desc diff --git a/src/selectors.cc b/src/selectors.cc index baa2d9ac8..c7e126b39 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -560,7 +560,7 @@ select_paragraph(const Context& context, const Selection& selection, BufferIterator first = buffer.iterator_at(selection.cursor()); if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and - is_eol(*(first-1)) and is_eol(*(first-2))) + is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2))) --first; else if ((flags & ObjectFlags::ToEnd) and first != buffer.begin() and (first+1) != buffer.end() and diff --git a/test/regression/3489-crash-on-paragraph-begin/cmd b/test/regression/3489-crash-on-paragraph-begin/cmd new file mode 100644 index 000000000..957dd0c19 --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/cmd @@ -0,0 +1 @@ +jp diff --git a/test/regression/3489-crash-on-paragraph-begin/in b/test/regression/3489-crash-on-paragraph-begin/in new file mode 100644 index 000000000..139597f9c --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/in @@ -0,0 +1,2 @@ + + diff --git a/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc b/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc new file mode 100644 index 000000000..ac6a6d5b2 --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc @@ -0,0 +1 @@ +2.1,1.1