From 3921b234e785128e2c05e3f719352cbd263e6026 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Mar 2015 18:44:11 +0000 Subject: [PATCH] Store fake keystrokes when selecting an insert completion candidate Instead of storing the real 'select next completion' keystroke, generate fake backspace/delete/char keystrokes so that replay of the insert will insert the exact same text. Fixes #135 --- src/input_handler.cc | 6 ++++-- src/insert_completer.cc | 9 ++++++++- src/insert_completer.hh | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) 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();