summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-03-22 22:06:11 +1100
committerMaxime Coste <mawww@kakoune.org>2024-03-22 22:06:11 +1100
commit6598d7b1b2d4d69f805288384b72a076666ca5ca (patch)
tree9ce4300047e63f53cb1ac11c0b8235a0f88a9ece /src/input_handler.cc
parentd5f7cbad87331583717493ca701010f72c2d4f74 (diff)
Fix invalid access when recording keys
<c-n>/<c-p> handling in insert was always dropping the last key in the last_insert() vector (in order to replace it with the actual completion text inserted), this was not valid for synthetized keys that are not added to that vector in the first place. Take the opportunity to merge insert completion handling code between <c-n>/<c-p> and direct menu selection. Fixes #5120
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 9d81f711..5800a6a0 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -1191,7 +1191,7 @@ public:
}
}
- void on_key(Key key, bool) override
+ void on_key(Key key, bool synthesized) override
{
auto& buffer = context().buffer();
@@ -1289,22 +1289,13 @@ public:
}, "enter register name", register_doc.str());
update_completions = false;
}
- else if (key == ctrl('n'))
- {
- last_insert().keys.pop_back();
- m_completer.select(1, true, last_insert().keys);
- update_completions = false;
- }
- else if (key == ctrl('p'))
- {
- last_insert().keys.pop_back();
- m_completer.select(-1, true, last_insert().keys);
- update_completions = false;
- }
- else if (key.modifiers == Key::Modifiers::MenuSelect)
+ else if (key == ctrl('n') or key == ctrl('p') or key.modifiers == Key::Modifiers::MenuSelect)
{
- last_insert().keys.pop_back();
- m_completer.select(key.key, false, last_insert().keys);
+ if (not synthesized)
+ last_insert().keys.pop_back();
+ bool relative = key.modifiers != Key::Modifiers::MenuSelect;
+ int index = relative ? (key == ctrl('n') ? 1 : -1) : key.key;
+ m_completer.select(index, relative, last_insert().keys);
update_completions = false;
}
else if (key == ctrl('x'))