1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 09:07:19 +03:00

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:
RegisterRestorer(char name)
: m_name(name),
m_save(RegisterManager::instance()[name].content())
{}
: m_name(name)
{
memoryview<String> save = RegisterManager::instance()[name];
m_save = std::vector<String>(save.begin(), save.end());
}
~RegisterRestorer()
{ RegisterManager::instance()[m_name] = m_save; }

View File

@ -210,7 +210,7 @@ void do_search(Editor& editor)
{
String ex = prompt("/");
if (ex.empty())
ex = RegisterManager::instance()['/'].get();
ex = RegisterManager::instance()['/'][0];
else
RegisterManager::instance()['/'] = ex;
@ -222,7 +222,7 @@ void do_search(Editor& editor)
template<bool append>
void do_search_next(Editor& editor)
{
const String& ex = RegisterManager::instance()['/'].get();
const String& ex = RegisterManager::instance()['/'][0];
if (not ex.empty())
editor.select(std::bind(select_next_match, _1, ex), append);
else
@ -260,9 +260,9 @@ void do_paste(Editor& editor, int count)
else
{
if (append)
editor.append(reg.get(count-1));
editor.append(reg[count-1]);
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'):
{
c = getch();
String reg = RegisterManager::instance()[c].get();
String reg = RegisterManager::instance()[c][0];
current_completion = -1;
result = result.substr(0, cursor_pos) + reg + result.substr(cursor_pos, String::npos);
cursor_pos += reg.length();

View File

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

View File

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