From 25a31534ec3b306f6ed438d77adcd798f9a20de5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 30 Apr 2016 10:37:31 +0100 Subject: [PATCH] Fix splitting selecting the first buffer char when there is a match at buffer begin --- src/selectors.cc | 9 +++++++-- test/unit/split-at-begin/cmd | 1 + test/unit/split-at-begin/in | 1 + test/unit/split-at-begin/selections | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/unit/split-at-begin/cmd create mode 100644 test/unit/split-at-begin/in create mode 100644 test/unit/split-at-begin/selections diff --git a/src/selectors.cc b/src/selectors.cc index 1ca42a28..65526b77 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -654,6 +654,7 @@ void split_selections(SelectionList& selections, const Regex& regex, unsigned ca Vector result; auto& buffer = selections.buffer(); auto buf_end = buffer.end(); + auto buf_begin = buffer.begin(); for (auto& sel : selections) { auto begin = buffer.iterator_at(sel.min()); @@ -671,8 +672,12 @@ void split_selections(SelectionList& selections, const Regex& regex, unsigned ca if (end == buf_end) continue; - end = ensure_char_start(buffer, end); - result.push_back(keep_direction({ begin.coord(), (begin == end) ? end.coord() : utf8::previous(end, begin).coord() }, sel)); + if (end != buf_begin) + { + end = ensure_char_start(buffer, end); + auto sel_end = (begin == end) ? end : utf8::previous(end, begin); + result.push_back(keep_direction({ begin.coord(), sel_end.coord() }, sel)); + } begin = ensure_char_start(buffer, (*re_it)[capture].second); } if (begin.coord() <= sel.max()) diff --git a/test/unit/split-at-begin/cmd b/test/unit/split-at-begin/cmd new file mode 100644 index 00000000..f2acbb71 --- /dev/null +++ b/test/unit/split-at-begin/cmd @@ -0,0 +1 @@ +%S\w+ diff --git a/test/unit/split-at-begin/in b/test/unit/split-at-begin/in new file mode 100644 index 00000000..1aeaedbf --- /dev/null +++ b/test/unit/split-at-begin/in @@ -0,0 +1 @@ +foo bar baz diff --git a/test/unit/split-at-begin/selections b/test/unit/split-at-begin/selections new file mode 100644 index 00000000..dd81dec5 --- /dev/null +++ b/test/unit/split-at-begin/selections @@ -0,0 +1,2 @@ + : : +