diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-08-09 18:33:32 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-08-12 20:02:11 +1000 |
| commit | 6ed01f402b3a54495c8d9e462b7674864fbbe402 (patch) | |
| tree | 2a5c3fcb1da1c8577fe58a87fdd3376c44b8ba49 /src/selection.cc | |
| parent | 1b2100753e4bdc65b1c6a78662ab5eeb7eaaa8d3 (diff) | |
Reduce headers dependency graph
Move more code into the implementation files to reduce the amount
of code pulled by headers.
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/selection.cc b/src/selection.cc index f0f0270c..03dd4721 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -7,6 +7,8 @@ namespace Kakoune { +SelectionList::~SelectionList() = default; + SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp) : m_selections({ std::move(s) }), m_buffer(&buffer), m_timestamp(timestamp) { @@ -27,6 +29,11 @@ SelectionList::SelectionList(Buffer& buffer, Vector<Selection> list, size_t time SelectionList::SelectionList(Buffer& buffer, Vector<Selection> list) : SelectionList(buffer, std::move(list), buffer.timestamp()) {} +SelectionList::SelectionList(const SelectionList&) = default; +SelectionList::SelectionList(SelectionList&&) = default; +SelectionList& SelectionList::operator=(const SelectionList&) = default; +SelectionList& SelectionList::operator=(SelectionList&&) = default; + void SelectionList::remove(size_t index) { m_selections.erase(begin() + index); @@ -538,4 +545,31 @@ Selection selection_from_string(ColumnType column_type, const Buffer& buffer, St return Selection{anchor, cursor}; } +SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView<String> descs, size_t timestamp, size_t main, ColumnCount tabstop) +{ + if ((column_type != ColumnType::Byte and timestamp != buffer.timestamp()) or timestamp > buffer.timestamp()) + throw runtime_error{format("invalid timestamp '{}'", timestamp)}; + + auto from_string = [&](StringView desc) { + return selection_from_string(column_type, buffer, desc, tabstop); + }; + + auto sels = descs | transform(from_string) | gather<Vector<Selection>>(); + if (sels.empty()) + throw runtime_error{"empty selection description"}; + if (main >= sels.size()) + throw runtime_error{"invalid main selection index"}; + + sort_selections(sels, main); + merge_overlapping_selections(sels, main); + if (timestamp < buffer.timestamp()) + update_selections(sels, main, buffer, timestamp); + else + clamp_selections(sels, buffer); + + SelectionList res{buffer, std::move(sels)}; + res.set_main_index(main); + return res; +} + } |
