save and restore " and / registers in exec_keys

This commit is contained in:
Maxime Coste 2012-02-27 19:51:30 +00:00
parent 13d74414e1
commit c03506ca04
2 changed files with 20 additions and 1 deletions

View File

@ -798,6 +798,22 @@ std::unordered_map<Key, std::function<void (Editor& editor, int count)>> keymap
{ { Key::Modifiers::Alt, 'x' }, [](Editor& editor, int count) { editor.select(select_whole_lines); } },
};
class RegisterRestorer
{
public:
RegisterRestorer(char name)
: m_name(name),
m_save(RegisterManager::instance()[name].content())
{}
~RegisterRestorer()
{ RegisterManager::instance()[m_name] = m_save; }
private:
std::vector<std::string> m_save;
char m_name;
};
void exec_keys(const KeyList& keys,
const Context& context)
{
@ -830,11 +846,13 @@ void exec_keys(const KeyList& keys,
return keys[pos++];
};
RegisterRestorer quote('"');
RegisterRestorer slash('/');
Editor batch_editor(context.buffer());
Editor& editor = context.has_window() ? static_cast<Editor&>(context.window())
: static_cast<Editor&>(batch_editor);
scoped_edition edition(editor);
int count = 0;

View File

@ -21,6 +21,7 @@ public:
operator memoryview<std::string>() const
{ return memoryview<std::string>(m_content); }
const std::vector<std::string>& content() const { return m_content; }
private:
std::vector<std::string> m_content;