Basic support for yanking and pasting

This commit is contained in:
Maxime Coste 2011-09-23 14:31:57 +00:00
parent 838ceb5958
commit 9b865cea39
2 changed files with 35 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "regex_selector.hh"
#include "command_manager.hh"
#include "buffer_manager.hh"
#include "register_manager.hh"
#include "selectors.hh"
#include "assert.hh"
@ -352,6 +353,16 @@ void do_search(Window& window)
catch (prompt_aborted&) {}
}
void do_yank(Window& window, int count)
{
RegisterManager::instance()['"'] = window.selection_content();
}
void do_paste(Window& window, int count)
{
window.append(RegisterManager::instance()['"']);
}
std::unordered_map<char, std::function<void (Window& window, int count)>> keymap =
{
{ 'h', [](Window& window, int count) { window.move_cursor(WindowCoord(0, -std::max(count,1))); window.empty_selections(); } },
@ -379,6 +390,9 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'g', do_go },
{ 'y', do_yank },
{ 'p', do_paste },
{ ':', [](Window& window, int count) { do_command(); } },
{ ' ', [](Window& window, int count) { window.empty_selections(); } },
{ 'w', [](Window& window, int count) { do { window.select(false, select_to_next_word); } while(--count > 0); } },
@ -401,6 +415,7 @@ int main(int argc, char* argv[])
CommandManager command_manager;
BufferManager buffer_manager;
RegisterManager register_manager;
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
PerArgumentCommandCompleter{ complete_filename });

20
src/register_manager.hh Normal file
View File

@ -0,0 +1,20 @@
#ifndef register_manager_hh_INCLUDED
#define register_manager_hh_INCLUDED
#include "utils.hh"
namespace Kakoune
{
class RegisterManager : public Singleton<RegisterManager>
{
public:
std::string& operator[](char reg) { return m_registers[reg]; }
protected:
std::unordered_map<char, std::string> m_registers;
};
}
#endif // register_manager_hh_INCLUDED