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
This commit is contained in:
Maxime Coste 2015-03-15 18:44:11 +00:00
parent b5854ece43
commit 3921b234e7
3 changed files with 13 additions and 4 deletions

View File

@ -879,12 +879,14 @@ public:
insert('\t'); insert('\t');
else if (key == ctrl('n')) else if (key == ctrl('n'))
{ {
m_completer.select(1); last_insert().second.pop_back();
m_completer.select(1, last_insert().second);
update_completions = false; update_completions = false;
} }
else if (key == ctrl('p')) else if (key == ctrl('p'))
{ {
m_completer.select(-1); last_insert().second.pop_back();
m_completer.select(-1, last_insert().second);
update_completions = false; update_completions = false;
} }
else if (key == ctrl('x')) else if (key == ctrl('x'))

View File

@ -245,7 +245,7 @@ InsertCompleter::~InsertCompleter()
m_options.unregister_watcher(*this); m_options.unregister_watcher(*this);
} }
void InsertCompleter::select(int offset) void InsertCompleter::select(int offset, Vector<Key>& keystrokes)
{ {
if (not setup_ifn()) if (not setup_ifn())
return; return;
@ -283,6 +283,13 @@ void InsertCompleter::select(int offset)
m_context.ui().info_show(candidate.first, candidate.second, CharCoord{}, m_context.ui().info_show(candidate.first, candidate.second, CharCoord{},
get_face("Information"), InfoStyle::MenuDoc); 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() void InsertCompleter::update()

View File

@ -60,7 +60,7 @@ public:
InsertCompleter& operator=(const InsertCompleter&) = delete; InsertCompleter& operator=(const InsertCompleter&) = delete;
~InsertCompleter(); ~InsertCompleter();
void select(int offset); void select(int offset, Vector<Key>& keystrokes);
void update(); void update();
void reset(); void reset();