1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 00:42:13 +03:00

Remove target_eol and small code cleanups

This commit is contained in:
Maxime Coste 2019-02-04 12:52:48 +11:00
parent d28dbd0918
commit 7f9fe32f2d
4 changed files with 9 additions and 20 deletions

View File

@ -2057,7 +2057,8 @@ void move_cursor(Context& context, NormalParams params)
void select_whole_buffer(Context& context, NormalParams) 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) void keep_selection(Context& context, NormalParams p)

View File

@ -8,6 +8,8 @@ namespace Kakoune
using CaptureList = Vector<String, MemoryDomain::Selections>; using CaptureList = Vector<String, MemoryDomain::Selections>;
constexpr ColumnCount max_column{std::numeric_limits<int>::max()};
// A selection is a Selection, associated with a CaptureList // A selection is a Selection, associated with a CaptureList
struct Selection struct Selection
{ {
@ -15,7 +17,7 @@ struct Selection
Selection() = default; Selection() = default;
Selection(BufferCoord pos) : Selection(pos,pos) {} Selection(BufferCoord pos) : Selection(pos,pos) {}
Selection(BufferCoord anchor, BufferCoord cursor, Selection(BufferCoord anchor, BufferCoordAndTarget cursor,
CaptureList captures = {}) CaptureList captures = {})
: m_anchor{anchor}, m_cursor{cursor}, : m_anchor{anchor}, m_cursor{cursor},
m_captures(std::move(captures)) {} m_captures(std::move(captures)) {}

View File

@ -21,12 +21,6 @@ using Utf8Iterator = utf8::iterator<BufferIterator>;
namespace namespace
{ {
Selection target_eol(Selection sel)
{
sel.cursor().target = INT_MAX;
return sel;
}
Selection utf8_range(const BufferIterator& first, const BufferIterator& last) Selection utf8_range(const BufferIterator& first, const BufferIterator& last)
{ {
return {first.coord(), last.coord()}; 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 selection.cursor() == BufferCoord{line, buffer[line].length() - 1} and
line != buffer.line_count() - 1) line != buffer.line_count() - 1)
++line; ++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> template<bool only_move>
@ -197,7 +191,7 @@ select_to_line_end(const Context& context, const Selection& selection)
buffer.iterator_at(line)).coord(); buffer.iterator_at(line)).coord();
if (end < begin) // Do not go backward when cursor is on eol if (end < begin) // Do not go backward when cursor is on eol
end = begin; 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<false>(const Context&, const Selection&);
template Optional<Selection> select_to_line_end<true>(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_start.column = 0;
to_line_end.column = buffer[to_line_end.line].length()-1; to_line_end.column = buffer[to_line_end.line].length()-1;
return target_eol({anchor, cursor}); return Selection{anchor, {cursor, max_column}};
} }
Optional<Selection> Optional<Selection>
@ -849,13 +843,7 @@ trim_partial_lines(const Context& context, const Selection& selection)
if (to_line_start > to_line_end) if (to_line_start > to_line_end)
return {}; return {};
return target_eol({anchor, cursor}); return Selection{anchor, {cursor, max_column}};
}
void select_buffer(SelectionList& selections)
{
auto& buffer = selections.buffer();
selections = SelectionList{ buffer, target_eol({{0,0}, buffer.back_coord()}) };
} }
static RegexExecFlags static RegexExecFlags

View File

@ -97,8 +97,6 @@ select_lines(const Context& context, const Selection& selection);
Optional<Selection> Optional<Selection>
trim_partial_lines(const Context& context, const Selection& selection); trim_partial_lines(const Context& context, const Selection& selection);
void select_buffer(SelectionList& selections);
enum class RegexMode; enum class RegexMode;
template<RegexMode mode> template<RegexMode mode>