Skip to content

Commit

Permalink
[fix-3600] Make insert repeat (.) more consistent
Browse files Browse the repository at this point in the history
Insert repeat will now only record non-synthesized keys, and when played back
execute mappings as well. Constructing some tests, and with the specific goal
of fixing alexherbo2/auto-pairs.kak#38, this appeared to
be the best approach. Other options could be evaluating the maps only when recording,
but this gave other issues (see tests/normal/repeat-insert/repeat-insert-mapped)

At this point, repeat-insert may be essentially just a hardcoded macro, at least I
haven't identified the difference. If this really is the case, it may make sense to
give it a dedicated register, and implement it as a macro.

Fixes mawww#3600
  • Loading branch information
topisani committed Feb 24, 2024
1 parent 6f97271 commit b626365
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/input_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ void InputHandler::repeat_last_insert()
// refill last_insert, this is very inefficient, but necessary at the moment
// to properly handle insert completion
m_last_insert.keys.push_back(key);
current_mode().handle_key(key, true);
handle_key(key);
}
kak_assert(dynamic_cast<InputModes::Normal*>(&current_mode()) != nullptr);
}
Expand Down Expand Up @@ -1655,11 +1655,12 @@ void InputHandler::handle_key(Key key)
auto dec = on_scope_end([this]{ --m_handle_key_level;} );

auto process_key = [&](Key key, bool synthesized) {
if (m_last_insert.recording)
m_last_insert.keys.push_back(key);
current_mode().handle_key(key, synthesized);
};

if (m_last_insert.recording and m_handle_key_level <= 1)
m_last_insert.keys.push_back(key);

const auto keymap_mode = current_mode().keymap_mode();
KeymapManager& keymaps = m_context.keymaps();
if (keymaps.is_mapped(key, keymap_mode) and not m_context.keymaps_disabled())
Expand Down
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-insert-hooks/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:hook -group h g InsertChar f %{exec FINSERTED}<ret>ifoo<esc>.\.\ifoo<esc>.
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-insert-hooks/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fFINSERTEDoofFINSERTEDoofoofoofoo
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-insert-mapped/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ixyz<esc>.
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-insert-mapped/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zzxx
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-insert-mapped/rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
map global insert y '<a-;>gh'
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-normal-exec/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i<a-;>:execute-keys foo<ret><esc>.
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-normal-exec/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foofoo
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-normal-movement/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ifoo<a-;>ghbar<esc>.
1 change: 1 addition & 0 deletions test/normal/repeat-insert/repeat-normal-movement/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
barbarfoofoo

0 comments on commit b626365

Please sign in to comment.