From 6ed01f402b3a54495c8d9e462b7674864fbbe402 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 9 Aug 2024 18:33:32 +1000 Subject: Reduce headers dependency graph Move more code into the implementation files to reduce the amount of code pulled by headers. --- src/selection.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/selection.cc') 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 list, size_t time SelectionList::SelectionList(Buffer& buffer, Vector 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 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>(); + 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; +} + } -- cgit v1.2.3 From 64ed046e5a841520506e1954ff0bd756ea112d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 16 Aug 2024 08:49:19 +0900 Subject: include headers cleanup --- src/selection.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/selection.cc') diff --git a/src/selection.cc b/src/selection.cc index 03dd4721..99b21c3e 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -2,7 +2,6 @@ #include "buffer_utils.hh" #include "changes.hh" -#include "utf8.hh" namespace Kakoune { -- cgit v1.2.3