diff --git a/src/input_handler.cc b/src/input_handler.cc index 313820da..b0c6b8b4 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -879,12 +879,14 @@ public: insert('\t'); else if (key == ctrl('n')) { - m_completer.select(1); + last_insert().second.pop_back(); + m_completer.select(1, last_insert().second); update_completions = false; } else if (key == ctrl('p')) { - m_completer.select(-1); + last_insert().second.pop_back(); + m_completer.select(-1, last_insert().second); update_completions = false; } else if (key == ctrl('x')) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 2207464a..073347a9 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -245,7 +245,7 @@ InsertCompleter::~InsertCompleter() m_options.unregister_watcher(*this); } -void InsertCompleter::select(int offset) +void InsertCompleter::select(int offset, Vector& keystrokes) { if (not setup_ifn()) return; @@ -283,6 +283,13 @@ void InsertCompleter::select(int offset) m_context.ui().info_show(candidate.first, candidate.second, CharCoord{}, get_face("Information"), InfoStyle::MenuDoc); } + + for (auto i = 0_byte; i < prefix_len; ++i) + keystrokes.push_back(Key::Backspace); + for (auto i = 0_byte; i < suffix_len; ++i) + keystrokes.push_back(Key::Delete); + for (auto& c : candidate.first) + keystrokes.push_back(c); } void InsertCompleter::update() diff --git a/src/insert_completer.hh b/src/insert_completer.hh index ffa2efdd..99fd1a58 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -60,7 +60,7 @@ public: InsertCompleter& operator=(const InsertCompleter&) = delete; ~InsertCompleter(); - void select(int offset); + void select(int offset, Vector& keystrokes); void update(); void reset();