diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-07-05 20:39:39 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-07-05 20:39:39 +1000 |
| commit | ec7986455947a34971f5084616b65800d1452b86 (patch) | |
| tree | ad7a5e7a9384e4c93b09973db46c735225c749f1 /src/input_handler.cc | |
| parent | 3fae7cd7c045f0a574ce83da574f0b678d1bc0ad (diff) | |
| parent | 163eb6dbc6758e84f8ce107632777fd06c8ac92d (diff) | |
Merge remote-tracking branch 'krobelus/allow-history-in-mappings'
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 08bcdd51..bbf9e7ea 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -788,6 +788,7 @@ public: m_prompt(prompt.str()), m_prompt_face(face), m_empty_text{std::move(emptystr)}, m_line_editor{context().faces()}, m_flags(flags), + m_was_interactive{not context().noninteractive()}, m_history{RegisterManager::instance()[history_register]}, m_current_history{-1}, m_auto_complete{context().options()["autocomplete"].get<AutoComplete>() & AutoComplete::Prompt}, @@ -1063,6 +1064,16 @@ public: } } + bool was_interactive() + { + return m_was_interactive; + } + + void set_was_interactive() + { + m_was_interactive = true; + } + DisplayLine mode_line() const override { return { "prompt", context().faces()["StatusLineMode"] }; @@ -1190,6 +1201,7 @@ private: LineEditor m_line_editor; bool m_line_changed = false; PromptFlags m_flags; + bool m_was_interactive; Register& m_history; int m_current_history; bool m_auto_complete; @@ -1198,7 +1210,7 @@ private: void history_push(StringView entry) { - if (entry.empty() or context().history_disabled() or + if (entry.empty() or not was_interactive() or (m_flags & PromptFlags::DropHistoryEntriesWithBlankPrefix and is_horizontal_blank(entry[0_byte]))) return; @@ -1706,11 +1718,17 @@ void InputHandler::prompt(StringView prompt, String initstr, String emptystr, void InputHandler::set_prompt_face(Face prompt_face) { - InputModes::Prompt* prompt = dynamic_cast<InputModes::Prompt*>(¤t_mode()); + auto* prompt = dynamic_cast<InputModes::Prompt*>(¤t_mode()); if (prompt) prompt->set_prompt_face(prompt_face); } +bool InputHandler::history_enabled() const +{ + auto* prompt = dynamic_cast<InputModes::Prompt*>(¤t_mode()); + return prompt and prompt->was_interactive(); +} + void InputHandler::menu(Vector<DisplayLine> choices, MenuCallback callback) { push_mode(new InputModes::Menu(*this, std::move(choices), std::move(callback))); @@ -1761,7 +1779,13 @@ void InputHandler::handle_key(Key key) const bool was_recording = is_recording(); ++m_handle_key_level; - auto dec = on_scope_end([this]{ --m_handle_key_level; }); + auto dec = on_scope_end([this]{ + --m_handle_key_level; + if (m_handle_key_level == 0) + for (auto& mode : m_mode_stack) + if (auto* prompt = dynamic_cast<InputModes::Prompt*>(&*mode)) + prompt->set_was_interactive(); + }); auto process_key = [&](Key key) { if (m_last_insert.recording) @@ -1773,7 +1797,7 @@ void InputHandler::handle_key(Key key) KeymapManager& keymaps = m_context.keymaps(); if (keymaps.is_mapped(key, keymap_mode) and not m_context.keymaps_disabled()) { - ScopedSetBool disable_history{context().history_disabled()}; + ScopedSetBool noninteractive{context().noninteractive()}; for (auto& k : keymaps.get_mapping_keys(key, keymap_mode)) process_key(k); |
