summaryrefslogtreecommitdiff
path: root/src/selection.hh
diff options
context:
space:
mode:
authorJason Felice <jason.m.felice@gmail.com>2019-11-11 21:06:37 -0500
committerMaxime Coste <mawww@kakoune.org>2019-11-12 20:54:32 +1100
commit5fae16faefe65464a37322390be3bb291cc3bafd (patch)
tree996f8dcdd271cea453aeceb2dea9e4985e323195 /src/selection.hh
parent6eb820dc54c96100909a179f2a58bbb9b00b51cd (diff)
Implement %val{selections_char_desc}
Fixes #3194
Diffstat (limited to 'src/selection.hh')
-rw-r--r--src/selection.hh23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/selection.hh b/src/selection.hh
index 5c47f878..568b438a 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -95,7 +95,6 @@ struct SelectionList
SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp);
void update(bool merge = true);
-
void check_invariant() const;
const Selection& main() const { return (*this)[m_main]; }
@@ -157,9 +156,27 @@ private:
Vector<Selection> compute_modified_ranges(const Buffer& buffer, size_t timestamp);
-String selection_to_string(const Selection& selection);
-String selection_list_to_string(const SelectionList& selection);
Selection selection_from_string(StringView desc);
+String selection_to_string(const Selection& selection);
+String selection_to_string_char(const Buffer& buffer, const Selection& selection);
+
+template<bool char_columns>
+String selection_list_to_string(const SelectionList& selections)
+{
+ auto& buffer = selections.buffer();
+ kak_assert(selections.timestamp() == buffer.timestamp());
+
+ auto to_string = [&](const Selection& selection) {
+ return char_columns ? selection_to_string_char(buffer, selection)
+ : selection_to_string(selection);
+ };
+
+ auto beg = &*selections.begin(), end = &*selections.end();
+ auto main = beg + selections.main_index();
+ using View = ConstArrayView<Selection>;
+ return join(concatenated(View{main, end}, View{beg, main}) |
+ transform(to_string), ' ', false);
+}
template<class StringArray>
SelectionList selection_list_from_strings(Buffer& buffer, StringArray&& descs, size_t timestamp, size_t main)