From 6598d7b1b2d4d69f805288384b72a076666ca5ca Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 22 Mar 2024 22:06:11 +1100 Subject: Fix invalid access when recording keys / 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 / and direct menu selection. Fixes #5120 --- src/input_handler.cc | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/input_handler.cc') 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')) -- cgit v1.2.3