diff --git a/src/normal.cc b/src/normal.cc index 9ffc4bd91..c0370015f 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 493a01b4e..c08bca9c6 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -8,6 +8,8 @@ namespace Kakoune using CaptureList = Vector; +constexpr ColumnCount max_column{std::numeric_limits::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 b618fab0d..e33dc21ec 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -21,12 +21,6 @@ using Utf8Iterator = utf8::iterator; 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 @@ -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 select_to_line_end(const Context&, const Selection&); template Optional select_to_line_end(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 @@ -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 d27b84ad5..2f0b4dc70 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -97,8 +97,6 @@ select_lines(const Context& context, const Selection& selection); Optional trim_partial_lines(const Context& context, const Selection& selection); -void select_buffer(SelectionList& selections); - enum class RegexMode; template