From 12310418b0a577fc0b60f0aae60503462073eb75 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 24 Jun 2023 19:49:02 +0200 Subject: Allow map/unmap during mapping execution Commits e49c0fb04 (unmap: fail if the mapping is currently executing, 2023-05-14) 42be0057a (map: fail if key is currently executing, 2023-06-24) fixed potential use-after-free issues. By doing so, it broke configurations that in practice have not triggered any crashes [1] [2]. For example with, set -remove global autocomplete insert hook global InsertCompletionShow .* %{ map window insert } hook global InsertCompletionHide .* %{ unmap window insert } The execution of the mapping triggers InsertCompletionHide fails at unmapping. This seems legit and I don't see an obvious alternative way to write it (InsertIdle would not be correct though it would work in practice). Fix the regression by allowing map and unmap again while keeping the mappings alive until they have finished executing. Applying map/unmap immediately seems like the most obvious semantics. Alternatively, we could apply them in between key presses. [1]: [2]: --- src/keymap_manager.hh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/keymap_manager.hh') diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index 9f9a6ab0..208b44f1 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -40,9 +40,7 @@ public: KeyList get_mapped_keys(KeymapMode mode) const; auto get_mapping_keys(Key key, KeymapMode mode) { - struct Keys : ConstArrayView { ScopedSetBool executing; }; - auto& mapping = get_mapping(key, mode); - return Keys{mapping.keys, mapping.is_executing}; + return get_mapping(key, mode).keys; } const String& get_mapping_docstring(Key key, KeymapMode mode) { return get_mapping(key, mode).docstring; } @@ -60,9 +58,8 @@ private: { KeyList keys; String docstring; - NestedBool is_executing{}; }; - KeymapInfo& get_mapping(Key key, KeymapMode mode); + const KeymapInfo& get_mapping(Key key, KeymapMode mode) const; KeymapManager() : m_parent(nullptr) {} -- cgit v1.2.3