diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-11-27 18:25:14 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-11-27 18:25:14 +1100 |
| commit | e0b9327a9f53469b3ed8f1b7e7e1f04d9068c539 (patch) | |
| tree | 306acc9c3422a0a06e1b308c49987e7144aca7ec | |
| parent | 46101662639b5e623137a02e64cc9fa94ebcf22a (diff) | |
| parent | 3d79107773c2b734982e6236188984dd8d20343d (diff) | |
Merge remote-tracking branch 'lenormf/fix-trim-selections'
| -rw-r--r-- | doc/pages/keys.asciidoc | 3 | ||||
| -rw-r--r-- | src/normal.cc | 21 |
2 files changed, 20 insertions, 4 deletions
diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 63e8b55f..f37e049c 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -324,7 +324,8 @@ Yanking (copying) and pasting use the *"* register by default (See <<registers#, option or the count parameter for tabstop *_*:: - trim selections + unselect whitespace surrounding each selection, drop those that only + contain whitespace *<a-)>*:: rotate selections content, if specified, the count groups selections, diff --git a/src/normal.cc b/src/normal.cc index 40200029..49cc90f6 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1711,17 +1711,32 @@ void spaces_to_tabs(Context& context, NormalParams params) void trim_selections(Context& context, NormalParams) { auto& buffer = context.buffer(); - for (auto& sel : context.selections()) + auto& selections = context.selections(); + Vector<int> to_remove; + + for (int i = 0; i < (int)selections.size(); ++i) { + auto& sel = selections[i]; auto beg = buffer.iterator_at(sel.min()); auto end = buffer.iterator_at(sel.max()); while (beg != end and is_blank(*beg)) ++beg; while (beg != end and is_blank(*end)) --end; - sel.min() = beg.coord(); - sel.max() = end.coord(); + + if (beg == end and is_blank(*beg)) + to_remove.push_back(i); + else + { + sel.min() = beg.coord(); + sel.max() = end.coord(); + } } + + if (to_remove.size() == selections.size()) + throw runtime_error{"no selections remaining"}; + for (auto& i : to_remove | reverse()) + selections.remove(i); } SelectionList read_selections_from_register(char reg, Context& context) |
