From aeae2fba37c62e1603bb4c9bd589534090eef6ed Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 2 Aug 2022 12:51:40 +0200 Subject: [PATCH] Pass entire context to select_coord This allows a following commit to record selection history inside select_coord() instead of at every call site. --- src/normal.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 69adfc785..0a559b472 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -140,8 +140,10 @@ void select_and_set_last(Context& context, Func&& func) } template -void select_coord(Buffer& buffer, BufferCoord coord, SelectionList& selections) +void select_coord(Context& context, BufferCoord coord) { + Buffer& buffer = context.buffer(); + SelectionList& selections = context.selections(); coord = buffer.clamp(coord); if (mode == SelectMode::Replace) selections = SelectionList{ buffer, coord }; @@ -212,7 +214,7 @@ void goto_commands(Context& context, NormalParams params) if (params.count != 0) { context.push_jump(); - select_coord(context.buffer(), LineCount{params.count - 1}, context.selections()); + select_coord(context, LineCount{params.count - 1}); if (context.has_window()) context.window().center_line(LineCount{params.count-1}); } @@ -229,7 +231,7 @@ void goto_commands(Context& context, NormalParams params) case 'g': case 'k': context.push_jump(); - select_coord(buffer, BufferCoord{0,0}, context.selections()); + select_coord(context, BufferCoord{0,0}); break; case 'l': select>(context, {}); @@ -242,17 +244,17 @@ void goto_commands(Context& context, NormalParams params) break; case 'j': context.push_jump(); - select_coord(buffer, buffer.line_count() - 1, context.selections()); + select_coord(context, buffer.line_count() - 1); break; case 'e': context.push_jump(); - select_coord(buffer, buffer.back_coord(), context.selections()); + select_coord(context, buffer.back_coord()); break; case 't': if (context.has_window()) { auto line = context.window().position().line; - select_coord(buffer, line, context.selections()); + select_coord(context, line); } break; case 'b': @@ -260,7 +262,7 @@ void goto_commands(Context& context, NormalParams params) { auto& window = context.window(); auto line = window.position().line + window.dimensions().line - 1; - select_coord(buffer, line, context.selections()); + select_coord(context, line); } break; case 'c': @@ -268,7 +270,7 @@ void goto_commands(Context& context, NormalParams params) { auto& window = context.window(); auto line = window.position().line + window.dimensions().line / 2; - select_coord(buffer, line, context.selections()); + select_coord(context, line); } break; case 'a': @@ -328,7 +330,7 @@ void goto_commands(Context& context, NormalParams params) throw runtime_error("no last modification position"); if (*pos >= buffer.back_coord()) pos = buffer.back_coord(); - select_coord(buffer, *pos, context.selections()); + select_coord(context, *pos); break; } default: