summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2022-12-03 16:50:29 +0100
committerJohannes Altmanninger <aclopte@gmail.com>2022-12-27 18:24:55 +0100
commita50cb5f6e7969183c69b56578ad63cb61fe06227 (patch)
treef12f9e568eca2c4d786f8a12037b8dc525dd6991 /src/normal.cc
parent938be7a7b0fb0753329bc74735e4d9d2132ea28c (diff)
Share logic for undo/redo selection changes
I will suggest a few changes to this code. No functional change.
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 1142d871..7dc14382 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1417,8 +1417,6 @@ void select_object(Context& context, NormalParams params)
{{alt(';')}, "run command in object context"}}));
}
-enum Direction { Backward = -1, Forward = 1 };
-
template<Direction direction, bool half = false>
void scroll(Context& context, NormalParams params)
{
@@ -2039,18 +2037,12 @@ void move_in_history(Context& context, NormalParams params)
history_id, max_history_id));
}
+template<Direction direction>
void undo_selection_change(Context& context, NormalParams params)
{
int count = std::max(1, params.count);
while (count--)
- context.undo_selection_change();
-}
-
-void redo_selection_change(Context& context, NormalParams params)
-{
- int count = std::max(1, params.count);
- while (count--)
- context.redo_selection_change();
+ context.undo_selection_change<direction>();
}
void exec_user_mappings(Context& context, NormalParams params)
@@ -2378,8 +2370,8 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {alt('u')}, {"move backward in history", move_in_history<Direction::Backward>} },
{ {alt('U')}, {"move forward in history", move_in_history<Direction::Forward>} },
- { {ctrl('h')}, {"undo selection change", undo_selection_change} },
- { {ctrl('k')}, {"redo selection change", redo_selection_change} },
+ { {ctrl('h')}, {"undo selection change", undo_selection_change<Backward>} },
+ { {ctrl('k')}, {"redo selection change", undo_selection_change<Forward>} },
{ {alt('i')}, {"select inner object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner>} },
{ {alt('a')}, {"select whole object", select_object<ObjectFlags::ToBegin | ObjectFlags::ToEnd>} },