From ffff4711c51c1a7aacdd40ab10be03fdcf627455 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 28 Jan 2015 22:33:29 +0000 Subject: [PATCH] Add history memory domain --- src/input_handler.cc | 33 +++++++++++++++++---------------- src/memory.hh | 2 ++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index afc6aecf..354fa973 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -476,18 +476,6 @@ String common_prefix(ArrayView strings) return res; } -void history_push(Vector& history, StringView entry) -{ - if(entry.empty()) - { - return; - } - Vector::iterator it; - while ((it = find(history, entry)) != history.end()) - history.erase(it); - history.push_back(entry); -} - class Prompt : public InputMode { public: @@ -507,7 +495,7 @@ public: void on_key(Key key) override { - Vector& history = ms_history[m_prompt]; + History& history = ms_history[m_prompt]; const String& line = m_line_editor.line(); bool showcompl = false; @@ -739,10 +727,23 @@ private: bool m_autoshowcompl; Mode m_mode = Mode::Default; - static UnorderedMap> ms_history; - Vector::iterator m_history_it; + using History = Vector; + static UnorderedMap ms_history; + History::iterator m_history_it; + + static void history_push(History& history, StringView entry) + { + if(entry.empty()) + { + return; + } + History::iterator it; + while ((it = find(history, entry)) != history.end()) + history.erase(it); + history.push_back(entry); + } }; -UnorderedMap> Prompt::ms_history; +UnorderedMap Prompt::ms_history; class NextKey : public InputMode { diff --git a/src/memory.hh b/src/memory.hh index 5fb52a17..a31e83c9 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -31,6 +31,7 @@ enum class MemoryDomain Client, WordDB, Selections, + History, Count }; @@ -57,6 +58,7 @@ inline const char* domain_name(MemoryDomain domain) case MemoryDomain::Registers: return "Registers"; case MemoryDomain::Client: return "Client"; case MemoryDomain::Selections: return "Selections"; + case MemoryDomain::History: return "History"; case MemoryDomain::Count: break; } kak_assert(false);