summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-02-04 12:52:48 +1100
committerMaxime Coste <mawww@kakoune.org>2019-02-04 12:52:48 +1100
commit7f9fe32f2d2c1946df568a98dd82c1e851a1bb4a (patch)
treed308be5253e992f34d0a5a3790165364cfc446c5 /src
parentd28dbd09182432e0cb85ecc5a2e7d062428c292f (diff)
Remove target_eol and small code cleanups
Diffstat (limited to 'src')
-rw-r--r--src/normal.cc3
-rw-r--r--src/selection.hh4
-rw-r--r--src/selectors.cc20
-rw-r--r--src/selectors.hh2
4 files changed, 9 insertions, 20 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 9ffc4bd9..c0370015 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -2057,7 +2057,8 @@ void move_cursor(Context& context, NormalParams params)
void select_whole_buffer(Context& context, NormalParams)
{
- select_buffer(context.selections());
+ auto& buffer = context.buffer();
+ context.selections_write_only() = SelectionList{buffer, {{0,0}, {buffer.back_coord(), max_column}}};
}
void keep_selection(Context& context, NormalParams p)
diff --git a/src/selection.hh b/src/selection.hh
index 493a01b4..c08bca9c 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -8,6 +8,8 @@ namespace Kakoune
using CaptureList = Vector<String, MemoryDomain::Selections>;
+constexpr ColumnCount max_column{std::numeric_limits<int>::max()};
+
// A selection is a Selection, associated with a CaptureList
struct Selection
{
@@ -15,7 +17,7 @@ struct Selection
Selection() = default;
Selection(BufferCoord pos) : Selection(pos,pos) {}
- Selection(BufferCoord anchor, BufferCoord cursor,
+ Selection(BufferCoord anchor, BufferCoordAndTarget cursor,
CaptureList captures = {})
: m_anchor{anchor}, m_cursor{cursor},
m_captures(std::move(captures)) {}
diff --git a/src/selectors.cc b/src/selectors.cc
index b618fab0..e33dc21e 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -21,12 +21,6 @@ using Utf8Iterator = utf8::iterator<BufferIterator>;
namespace
{
-Selection target_eol(Selection sel)
-{
- sel.cursor().target = INT_MAX;
- return sel;
-}
-
Selection utf8_range(const BufferIterator& first, const BufferIterator& last)
{
return {first.coord(), last.coord()};
@@ -183,7 +177,7 @@ select_line(const Context& context, const Selection& selection)
selection.cursor() == BufferCoord{line, buffer[line].length() - 1} and
line != buffer.line_count() - 1)
++line;
- return target_eol({{line, 0_byte}, {line, buffer[line].length() - 1}});
+ return Selection{{line, 0_byte}, {line, buffer[line].length() - 1, max_column}};
}
template<bool only_move>
@@ -197,7 +191,7 @@ select_to_line_end(const Context& context, const Selection& selection)
buffer.iterator_at(line)).coord();
if (end < begin) // Do not go backward when cursor is on eol
end = begin;
- return target_eol({only_move ? end : begin, end});
+ return Selection{only_move ? end : begin, {end, max_column}};
}
template Optional<Selection> select_to_line_end<false>(const Context&, const Selection&);
template Optional<Selection> select_to_line_end<true>(const Context&, const Selection&);
@@ -823,7 +817,7 @@ select_lines(const Context& context, const Selection& selection)
to_line_start.column = 0;
to_line_end.column = buffer[to_line_end.line].length()-1;
- return target_eol({anchor, cursor});
+ return Selection{anchor, {cursor, max_column}};
}
Optional<Selection>
@@ -849,13 +843,7 @@ trim_partial_lines(const Context& context, const Selection& selection)
if (to_line_start > to_line_end)
return {};
- return target_eol({anchor, cursor});
-}
-
-void select_buffer(SelectionList& selections)
-{
- auto& buffer = selections.buffer();
- selections = SelectionList{ buffer, target_eol({{0,0}, buffer.back_coord()}) };
+ return Selection{anchor, {cursor, max_column}};
}
static RegexExecFlags
diff --git a/src/selectors.hh b/src/selectors.hh
index d27b84ad..2f0b4dc7 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -97,8 +97,6 @@ select_lines(const Context& context, const Selection& selection);
Optional<Selection>
trim_partial_lines(const Context& context, const Selection& selection);
-void select_buffer(SelectionList& selections);
-
enum class RegexMode;
template<RegexMode mode>