summaryrefslogtreecommitdiff
path: root/src/selection.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-08-09 18:33:32 +1000
committerMaxime Coste <mawww@kakoune.org>2024-08-12 20:02:11 +1000
commit6ed01f402b3a54495c8d9e462b7674864fbbe402 (patch)
tree2a5c3fcb1da1c8577fe58a87fdd3376c44b8ba49 /src/selection.hh
parent1b2100753e4bdc65b1c6a78662ab5eeb7eaaa8d3 (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.hh')
-rw-r--r--src/selection.hh45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/selection.hh b/src/selection.hh
index 509a527d..ede4fa7b 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -1,13 +1,21 @@
#ifndef selection_hh_INCLUDED
#define selection_hh_INCLUDED
-#include "buffer.hh"
+#include "coord.hh"
+#include "range.hh"
+#include "safe_ptr.hh"
+#include "utils.hh"
+#include "string.hh"
+#include "vector.hh"
#include <limits>
namespace Kakoune
{
+class Buffer;
+using BufferRange = Range<BufferCoord>;
+
using CaptureList = Vector<String, MemoryDomain::Selections>;
constexpr ColumnCount max_column{std::numeric_limits<int>::max()};
@@ -84,11 +92,18 @@ struct SelectionList
{
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
+ ~SelectionList();
SelectionList(Buffer& buffer, Selection s);
SelectionList(Buffer& buffer, Selection s, size_t timestamp);
SelectionList(Buffer& buffer, Vector<Selection> s);
SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp);
+ SelectionList(const SelectionList&);
+ SelectionList(SelectionList&&);
+
+ SelectionList& operator=(const SelectionList&);
+ SelectionList& operator=(SelectionList&&);
+
void update(bool merge = true);
void check_invariant() const;
@@ -166,33 +181,7 @@ String selection_to_string(ColumnType column_type, const Buffer& buffer, const S
String selection_list_to_string(ColumnType column_type, const SelectionList& selections, ColumnCount tabstop = -1);
-template<typename StringArray>
-SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, StringArray&& descs, size_t timestamp, size_t main, ColumnCount tabstop = -1)
-{
- 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;
-}
+SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView<String> descs, size_t timestamp, size_t main, ColumnCount tabstop = -1);
}