From 683ce8e83b0a4a3ae17567967f68539456a35ffc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 25 Mar 2018 11:25:55 +1100 Subject: [PATCH] Use 1 and -1 for Forward/Backward Direction to simplify code --- src/normal.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 968293b6..5d0659d0 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1293,7 +1293,7 @@ void select_object(Context& context, NormalParams params) {{'c'}, "custom object desc"}})); } -enum Direction { Forward, Backward }; +enum Direction { Backward = -1, Forward = 1 }; template void scroll(Context& context, NormalParams params) @@ -1302,7 +1302,7 @@ void scroll(Context& context, NormalParams params) const int count = params.count ? params.count : 1; const LineCount offset = (window.dimensions().line - 2) / (half ? 2 : 1) * count; - scroll_window(context, direction == Direction::Forward ? offset : -offset); + scroll_window(context, offset * direction); } template @@ -1327,7 +1327,7 @@ void copy_selections_on_next_lines(Context& context, NormalParams params) const LineCount height = std::max(anchor.line, cursor.line) - std::min(anchor.line, cursor.line) + 1; for (int i = 0; i < std::max(params.count, 1); ++i) { - LineCount offset = (direction == Forward ? 1 : -1) * (i + 1) * height; + LineCount offset = direction * (i + 1) * height; const LineCount anchor_line = anchor.line + offset; const LineCount cursor_line = cursor.line + offset; @@ -1867,8 +1867,7 @@ void move_in_history(Context& context, NormalParams params) Buffer& buffer = context.buffer(); size_t timestamp = buffer.timestamp(); const int count = std::max(1, params.count); - const int history_id = (int)buffer.current_history_id() + - (direction == Direction::Forward ? count : -count); + const int history_id = (int)buffer.current_history_id() + direction * count; const int max_history_id = (int)buffer.next_history_id() - 1; if (buffer.move_to((size_t)history_id)) { @@ -1945,9 +1944,7 @@ template(); auto& selections = context.selections(); for (auto& sel : selections)