diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-03-12 14:23:30 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-03-12 14:23:30 +0000 |
| commit | cd615b35a2a3b4e71d5f6232e307a8c4c07f834a (patch) | |
| tree | 896910716a19cca0adce65f1126135a9b4e11bce /src/selectors.cc | |
| parent | df0f7b46893b9c87d33df246b7012d4058a79eab (diff) | |
generalize do_select_surrounding in do_select_object and add a whole word selector
Diffstat (limited to 'src/selectors.cc')
| -rw-r--r-- | src/selectors.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/selectors.cc b/src/selectors.cc index bb88697f..bcad49a4 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -319,6 +319,34 @@ SelectionAndCaptures select_to_eol_reverse(const Selection& selection) return Selection(begin, end.is_begin() ? end : end+1); } +template<bool punctuation_is_word> +SelectionAndCaptures select_whole_word(const Selection& selection, bool inner) +{ + BufferIterator first = selection.last(); + BufferIterator last = first; + if (is_word(*first)) + { + if (not skip_while_reverse(first, is_word<punctuation_is_word>)) + ++first; + skip_while(last, is_word<punctuation_is_word>); + if (not inner) + skip_while(last, is_blank); + } + else if (not inner) + { + if (not skip_while_reverse(first, is_blank)) + ++first; + skip_while(last, is_blank); + if (not is_word<punctuation_is_word>(*last)) + return selection; + skip_while(last, is_word<punctuation_is_word>); + } + --last; + return Selection(first, last); +} +template SelectionAndCaptures select_whole_word<false>(const Selection&, bool); +template SelectionAndCaptures select_whole_word<true>(const Selection&, bool); + SelectionAndCaptures select_whole_lines(const Selection& selection) { BufferIterator first = selection.first(); |
