simplify Register interface

This commit is contained in:
Maxime Coste 2012-06-29 13:25:34 +02:00
parent 49e1d91804
commit 7aa533c049
5 changed files with 12 additions and 29 deletions

View File

@ -659,9 +659,11 @@ class RegisterRestorer
{ {
public: public:
RegisterRestorer(char name) RegisterRestorer(char name)
: m_name(name), : m_name(name)
m_save(RegisterManager::instance()[name].content()) {
{} memoryview<String> save = RegisterManager::instance()[name];
m_save = std::vector<String>(save.begin(), save.end());
}
~RegisterRestorer() ~RegisterRestorer()
{ RegisterManager::instance()[m_name] = m_save; } { RegisterManager::instance()[m_name] = m_save; }

View File

@ -210,7 +210,7 @@ void do_search(Editor& editor)
{ {
String ex = prompt("/"); String ex = prompt("/");
if (ex.empty()) if (ex.empty())
ex = RegisterManager::instance()['/'].get(); ex = RegisterManager::instance()['/'][0];
else else
RegisterManager::instance()['/'] = ex; RegisterManager::instance()['/'] = ex;
@ -222,7 +222,7 @@ void do_search(Editor& editor)
template<bool append> template<bool append>
void do_search_next(Editor& editor) void do_search_next(Editor& editor)
{ {
const String& ex = RegisterManager::instance()['/'].get(); const String& ex = RegisterManager::instance()['/'][0];
if (not ex.empty()) if (not ex.empty())
editor.select(std::bind(select_next_match, _1, ex), append); editor.select(std::bind(select_next_match, _1, ex), append);
else else
@ -260,9 +260,9 @@ void do_paste(Editor& editor, int count)
else else
{ {
if (append) if (append)
editor.append(reg.get(count-1)); editor.append(reg[count-1]);
else else
editor.insert(reg.get(count-1)); editor.insert(reg[count-1]);
} }
} }

View File

@ -265,7 +265,7 @@ String NCursesClient::prompt(const String& text, Completer completer)
case CTRL('r'): case CTRL('r'):
{ {
c = getch(); c = getch();
String reg = RegisterManager::instance()[c].get(); String reg = RegisterManager::instance()[c][0];
current_completion = -1; current_completion = -1;
result = result.substr(0, cursor_pos) + reg + result.substr(cursor_pos, String::npos); result = result.substr(0, cursor_pos) + reg + result.substr(cursor_pos, String::npos);
cursor_pos += reg.length(); cursor_pos += reg.length();

View File

@ -5,28 +5,13 @@ namespace Kakoune
const String Register::ms_empty; const String Register::ms_empty;
Register& Register::operator=(const String& value)
{
m_content.clear();
m_content.push_back(value);
return *this;
}
Register& Register::operator=(const memoryview<String>& values) Register& Register::operator=(const memoryview<String>& values)
{ {
m_content = std::vector<String>(values.begin(), values.end()); m_content = std::vector<String>(values.begin(), values.end());
return *this; return *this;
} }
const String& Register::get() const const String& Register::operator[](size_t index) const
{
if (m_content.size() != 0)
return m_content.front();
else
return ms_empty;
}
const String& Register::get(size_t index) const
{ {
if (m_content.size() > index) if (m_content.size() > index)
return m_content[index]; return m_content[index];

View File

@ -12,16 +12,12 @@ namespace Kakoune
class Register class Register
{ {
public: public:
Register& operator=(const String& value);
Register& operator=(const memoryview<String>& values); Register& operator=(const memoryview<String>& values);
const String& get() const; const String& operator[](size_t index) const;
const String& get(size_t index) const;
operator memoryview<String>() const operator memoryview<String>() const
{ return memoryview<String>(m_content); } { return memoryview<String>(m_content); }
const std::vector<String>& content() const { return m_content; }
private: private:
std::vector<String> m_content; std::vector<String> m_content;