add a Register class, registers can now contain a list of string
That way, registers can be used to store per selection data
This commit is contained in:
parent
9b5e9ffee2
commit
333e87dedd
18
src/main.cc
18
src/main.cc
|
@ -413,7 +413,7 @@ bool insert_char(IncrementalInserter& inserter, const Key& key)
|
|||
inserter.insert(inserter.buffer().name());
|
||||
break;
|
||||
default:
|
||||
inserter.insert(RegisterManager::instance()[next_key.key]);
|
||||
inserter.insert(RegisterManager::instance()[next_key.key].get());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -834,9 +834,9 @@ void do_search(Editor& editor)
|
|||
{
|
||||
std::string ex = prompt("/");
|
||||
if (ex.empty())
|
||||
ex = RegisterManager::instance()['/'];
|
||||
ex = RegisterManager::instance()['/'].get();
|
||||
else
|
||||
RegisterManager::instance()['/'] = ex;
|
||||
RegisterManager::instance()['/'].set(ex);
|
||||
|
||||
editor.select(std::bind(select_next_match, _1, ex));
|
||||
}
|
||||
|
@ -845,7 +845,7 @@ void do_search(Editor& editor)
|
|||
|
||||
void do_search_next(Editor& editor)
|
||||
{
|
||||
std::string& ex = RegisterManager::instance()['/'];
|
||||
const std::string& ex = RegisterManager::instance()['/'].get();
|
||||
if (not ex.empty())
|
||||
editor.select(std::bind(select_next_match, _1, ex));
|
||||
else
|
||||
|
@ -854,18 +854,18 @@ void do_search_next(Editor& editor)
|
|||
|
||||
void do_yank(Editor& editor, int count)
|
||||
{
|
||||
RegisterManager::instance()['"'] = editor.selection_content();
|
||||
RegisterManager::instance()['"'].set(editor.selection_content());
|
||||
}
|
||||
|
||||
void do_erase(Editor& editor, int count)
|
||||
{
|
||||
RegisterManager::instance()['"'] = editor.selection_content();
|
||||
RegisterManager::instance()['"'].set(editor.selection_content());
|
||||
editor.erase();
|
||||
}
|
||||
|
||||
void do_change(Editor& editor, int count)
|
||||
{
|
||||
RegisterManager::instance()['"'] = editor.selection_content();
|
||||
RegisterManager::instance()['"'].set(editor.selection_content());
|
||||
do_insert(editor, IncrementalInserter::Mode::Change);
|
||||
}
|
||||
|
||||
|
@ -873,9 +873,9 @@ template<bool append>
|
|||
void do_paste(Editor& editor, int count)
|
||||
{
|
||||
if (append)
|
||||
editor.append(RegisterManager::instance()['"']);
|
||||
editor.append(RegisterManager::instance()['"'].get());
|
||||
else
|
||||
editor.insert(RegisterManager::instance()['"']);
|
||||
editor.insert(RegisterManager::instance()['"'].get());
|
||||
}
|
||||
|
||||
void do_select_regex(Editor& editor, int count)
|
||||
|
|
35
src/register.cc
Normal file
35
src/register.cc
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "register.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
const std::string Register::ms_empty;
|
||||
|
||||
void Register::set(const std::string& value)
|
||||
{
|
||||
m_content.clear();
|
||||
m_content.push_back(value);
|
||||
}
|
||||
|
||||
void Register::set(const memoryview<std::string>& values)
|
||||
{
|
||||
m_content = std::vector<std::string>(values.begin(), values.end());
|
||||
}
|
||||
|
||||
const std::string& Register::get() const
|
||||
{
|
||||
if (m_content.size() != 0)
|
||||
return m_content.front();
|
||||
else
|
||||
return ms_empty;
|
||||
}
|
||||
|
||||
const std::string& Register::get(size_t index) const
|
||||
{
|
||||
if (m_content.size() > index)
|
||||
return m_content[index];
|
||||
else
|
||||
return ms_empty;
|
||||
}
|
||||
|
||||
}
|
29
src/register.hh
Normal file
29
src/register.hh
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef register_hh_INCLUDED
|
||||
#define register_hh_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "memoryview.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
class Register
|
||||
{
|
||||
public:
|
||||
void set(const std::string& value);
|
||||
void set(const memoryview<std::string>& values);
|
||||
const std::string& get() const;
|
||||
const std::string& get(size_t index) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_content;
|
||||
|
||||
static const std::string ms_empty;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // register_hh_INCLUDED
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef register_manager_hh_INCLUDED
|
||||
#define register_manager_hh_INCLUDED
|
||||
|
||||
#include "register.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
namespace Kakoune
|
||||
|
@ -9,10 +10,10 @@ namespace Kakoune
|
|||
class RegisterManager : public Singleton<RegisterManager>
|
||||
{
|
||||
public:
|
||||
std::string& operator[](char reg) { return m_registers[reg]; }
|
||||
Register& operator[](char reg) { return m_registers[reg]; }
|
||||
|
||||
protected:
|
||||
std::unordered_map<char, std::string> m_registers;
|
||||
std::unordered_map<char, Register> m_registers;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user