Use an Editor instead of a Window as much as possible

This commit is contained in:
Maxime Coste 2012-02-02 20:48:03 +00:00
parent 69d96c90da
commit 96101b4392
4 changed files with 120 additions and 121 deletions

View File

@ -243,11 +243,6 @@ void Buffer::delete_window(Window* window)
m_windows.erase(window_it); m_windows.erase(window_it);
} }
std::unique_ptr<Window> Buffer::create_temporary_window()
{
return std::unique_ptr<Window>(new Window(*this));
}
bool Buffer::is_modified() const bool Buffer::is_modified() const
{ {
size_t history_cursor_index = m_history_cursor - m_history.begin(); size_t history_cursor_index = m_history_cursor - m_history.begin();

View File

@ -151,8 +151,6 @@ public:
Window* get_or_create_window(); Window* get_or_create_window();
void delete_window(Window* window); void delete_window(Window* window);
std::unique_ptr<Window> create_temporary_window();
bool is_modified() const; bool is_modified() const;
Type type() const { return m_type; } Type type() const { return m_type; }
void notify_saved(); void notify_saved();

View File

@ -103,6 +103,8 @@ public:
void erase(); void erase();
void move_cursors(const BufferCoord& offset); void move_cursors(const BufferCoord& offset);
Buffer& buffer() const { return m_editor.buffer(); }
private: private:
void apply(Modification&& modification) const; void apply(Modification&& modification) const;

View File

@ -163,6 +163,13 @@ void draw_window(Window& window)
move(cursor_position.line, cursor_position.column); move(cursor_position.line, cursor_position.column);
} }
void draw_editor_ifn(Editor& editor)
{
Window* window = dynamic_cast<Window*>(&editor);
if (window)
draw_window(*window);
}
Key ncurses_get_key() Key ncurses_get_key()
{ {
char c = getch(); char c = getch();
@ -369,7 +376,7 @@ struct InsertSequence
InsertSequence last_insert_sequence; InsertSequence last_insert_sequence;
bool insert_char(Window& window, IncrementalInserter& inserter, const Key& key) bool insert_char(IncrementalInserter& inserter, const Key& key)
{ {
switch (key.modifiers) switch (key.modifiers)
{ {
@ -403,7 +410,7 @@ bool insert_char(Window& window, IncrementalInserter& inserter, const Key& key)
switch (next_key.key) switch (next_key.key)
{ {
case '%': case '%':
inserter.insert(window.buffer().name()); inserter.insert(inserter.buffer().name());
break; break;
default: default:
inserter.insert(RegisterManager::instance()[next_key.key]); inserter.insert(RegisterManager::instance()[next_key.key]);
@ -429,44 +436,44 @@ bool insert_char(Window& window, IncrementalInserter& inserter, const Key& key)
return true; return true;
} }
void do_insert(Window& window, IncrementalInserter::Mode mode) void do_insert(Editor& editor, IncrementalInserter::Mode mode)
{ {
last_insert_sequence.mode = mode; last_insert_sequence.mode = mode;
last_insert_sequence.keys.clear(); last_insert_sequence.keys.clear();
IncrementalInserter inserter(window, mode); IncrementalInserter inserter(editor, mode);
draw_window(window); draw_editor_ifn(editor);
while(true) while(true)
{ {
Key key = get_key(); Key key = get_key();
if (not insert_char(window, inserter, key)) if (not insert_char(inserter, key))
break; break;
last_insert_sequence.keys.push_back(key); last_insert_sequence.keys.push_back(key);
draw_window(window); draw_editor_ifn(editor);
} }
} }
void do_repeat_insert(Window& window, int count) void do_repeat_insert(Editor& editor, int count)
{ {
IncrementalInserter inserter(window, last_insert_sequence.mode); IncrementalInserter inserter(editor, last_insert_sequence.mode);
for (const Key& key : last_insert_sequence.keys) for (const Key& key : last_insert_sequence.keys)
{ {
insert_char(window, inserter, key); insert_char(inserter, key);
} }
draw_window(window); draw_editor_ifn(editor);
} }
template<bool append> template<bool append>
void do_go(Window& window, int count) void do_go(Editor& editor, int count)
{ {
if (count != 0) if (count != 0)
{ {
BufferIterator target = BufferIterator target =
window.buffer().iterator_at(BufferCoord(count-1, 0)); editor.buffer().iterator_at(BufferCoord(count-1, 0));
window.select(target); editor.select(target);
} }
else else
{ {
@ -480,23 +487,23 @@ void do_go(Window& window, int count)
case 't': case 't':
{ {
BufferIterator target = BufferIterator target =
window.buffer().iterator_at(BufferCoord(0,0)); editor.buffer().iterator_at(BufferCoord(0,0));
window.select(target); editor.select(target);
break; break;
} }
case 'l': case 'l':
case 'L': case 'L':
window.select(select_to_eol, append); editor.select(select_to_eol, append);
break; break;
case 'h': case 'h':
case 'H': case 'H':
window.select(select_to_eol_reverse, append); editor.select(select_to_eol_reverse, append);
break; break;
case 'b': case 'b':
{ {
BufferIterator target = window.buffer().iterator_at( BufferIterator target = editor.buffer().iterator_at(
BufferCoord(window.buffer().line_count() - 1, 0)); BufferCoord(editor.buffer().line_count() - 1, 0));
window.select(target); editor.select(target);
break; break;
} }
} }
@ -768,14 +775,14 @@ void do_command()
catch (prompt_aborted&) {} catch (prompt_aborted&) {}
} }
void do_pipe(Window& window, int count) void do_pipe(Editor& editor, int count)
{ {
try try
{ {
auto cmdline = prompt("|", complete_nothing); auto cmdline = prompt("|", complete_nothing);
window.buffer().begin_undo_group(); editor.buffer().begin_undo_group();
for (auto& sel : const_cast<const Window&>(window).selections()) for (auto& sel : const_cast<const Editor&>(editor).selections())
{ {
int write_pipe[2]; int write_pipe[2];
int read_pipe[2]; int read_pipe[2];
@ -788,7 +795,7 @@ void do_pipe(Window& window, int count)
close(write_pipe[0]); close(write_pipe[0]);
close(read_pipe[1]); close(read_pipe[1]);
std::string content = window.buffer().string(sel.begin(), sel.end()); std::string content = editor.buffer().string(sel.begin(), sel.end());
write(write_pipe[1], content.c_str(), content.size()); write(write_pipe[1], content.c_str(), content.size());
close(write_pipe[1]); close(write_pipe[1]);
@ -801,8 +808,8 @@ void do_pipe(Window& window, int count)
close(read_pipe[0]); close(read_pipe[0]);
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
window.buffer().modify(Modification::make_erase(sel.begin(), sel.end())); editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end()));
window.buffer().modify(Modification::make_insert(sel.begin(), new_content)); editor.buffer().modify(Modification::make_insert(sel.begin(), new_content));
} }
else else
{ {
@ -815,12 +822,12 @@ void do_pipe(Window& window, int count)
execlp("sh", "sh", "-c", cmdline.c_str(), NULL); execlp("sh", "sh", "-c", cmdline.c_str(), NULL);
} }
} }
window.buffer().end_undo_group(); editor.buffer().end_undo_group();
} }
catch (prompt_aborted&) {} catch (prompt_aborted&) {}
} }
void do_search(Window& window) void do_search(Editor& editor)
{ {
try try
{ {
@ -830,78 +837,78 @@ void do_search(Window& window)
else else
RegisterManager::instance()['/'] = ex; RegisterManager::instance()['/'] = ex;
window.select(std::bind(select_next_match, _1, ex)); editor.select(std::bind(select_next_match, _1, ex));
} }
catch (prompt_aborted&) {} catch (prompt_aborted&) {}
} }
void do_search_next(Window& window) void do_search_next(Editor& editor)
{ {
std::string& ex = RegisterManager::instance()['/']; std::string& ex = RegisterManager::instance()['/'];
if (not ex.empty()) if (not ex.empty())
window.select(std::bind(select_next_match, _1, ex)); editor.select(std::bind(select_next_match, _1, ex));
else else
print_status("no search pattern"); print_status("no search pattern");
} }
void do_yank(Window& window, int count) void do_yank(Editor& editor, int count)
{ {
RegisterManager::instance()['"'] = window.selection_content(); RegisterManager::instance()['"'] = editor.selection_content();
} }
void do_erase(Window& window, int count) void do_erase(Editor& editor, int count)
{ {
RegisterManager::instance()['"'] = window.selection_content(); RegisterManager::instance()['"'] = editor.selection_content();
window.erase(); editor.erase();
} }
void do_change(Window& window, int count) void do_change(Editor& editor, int count)
{ {
RegisterManager::instance()['"'] = window.selection_content(); RegisterManager::instance()['"'] = editor.selection_content();
do_insert(window, IncrementalInserter::Mode::Change); do_insert(editor, IncrementalInserter::Mode::Change);
} }
template<bool append> template<bool append>
void do_paste(Window& window, int count) void do_paste(Editor& editor, int count)
{ {
if (append) if (append)
window.append(RegisterManager::instance()['"']); editor.append(RegisterManager::instance()['"']);
else else
window.insert(RegisterManager::instance()['"']); editor.insert(RegisterManager::instance()['"']);
} }
void do_select_regex(Window& window, int count) void do_select_regex(Editor& editor, int count)
{ {
try try
{ {
std::string ex = prompt("select: "); std::string ex = prompt("select: ");
window.multi_select(std::bind(select_all_matches, _1, ex)); editor.multi_select(std::bind(select_all_matches, _1, ex));
} }
catch (prompt_aborted&) {} catch (prompt_aborted&) {}
} }
void do_split_regex(Window& window, int count) void do_split_regex(Editor& editor, int count)
{ {
try try
{ {
std::string ex = prompt("split: "); std::string ex = prompt("split: ");
window.multi_select(std::bind(split_selection, _1, ex)); editor.multi_select(std::bind(split_selection, _1, ex));
} }
catch (prompt_aborted&) {} catch (prompt_aborted&) {}
} }
void do_join(Window& window, int count) void do_join(Editor& editor, int count)
{ {
window.multi_select(select_whole_lines); editor.multi_select(select_whole_lines);
window.select(select_to_eol, true); editor.select(select_to_eol, true);
window.multi_select(std::bind(select_all_matches, _1, "\n\\h*")); editor.multi_select(std::bind(select_all_matches, _1, "\n\\h*"));
window.replace(" "); editor.replace(" ");
window.clear_selections(); editor.clear_selections();
window.move_selections({0, -1}); editor.move_selections({0, -1});
} }
template<bool inside> template<bool inside>
void do_select_surrounding(Window& window, int count) void do_select_surrounding(Editor& editor, int count)
{ {
char id = getch(); char id = getch();
@ -921,34 +928,34 @@ void do_select_surrounding(Window& window, int count)
auto matching = id_to_matching.find(id); auto matching = id_to_matching.find(id);
if (matching != id_to_matching.end()) if (matching != id_to_matching.end())
window.select(std::bind(select_surrounding, _1, matching->second, inside)); editor.select(std::bind(select_surrounding, _1, matching->second, inside));
} }
std::unordered_map<Key, std::function<void (Window& window, int count)>> keymap = std::unordered_map<Key, std::function<void (Editor& editor, int count)>> keymap =
{ {
{ { Key::Modifiers::None, 'h' }, [](Window& window, int count) { window.move_selections(BufferCoord(0, -std::max(count,1))); } }, { { Key::Modifiers::None, 'h' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(0, -std::max(count,1))); } },
{ { Key::Modifiers::None, 'j' }, [](Window& window, int count) { window.move_selections(BufferCoord( std::max(count,1), 0)); } }, { { Key::Modifiers::None, 'j' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord( std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'k' }, [](Window& window, int count) { window.move_selections(BufferCoord(-std::max(count,1), 0)); } }, { { Key::Modifiers::None, 'k' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(-std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'l' }, [](Window& window, int count) { window.move_selections(BufferCoord(0, std::max(count,1))); } }, { { Key::Modifiers::None, 'l' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(0, std::max(count,1))); } },
{ { Key::Modifiers::None, 'H' }, [](Window& window, int count) { window.move_selections(BufferCoord(0, -std::max(count,1)), true); } }, { { Key::Modifiers::None, 'H' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(0, -std::max(count,1)), true); } },
{ { Key::Modifiers::None, 'J' }, [](Window& window, int count) { window.move_selections(BufferCoord( std::max(count,1), 0), true); } }, { { Key::Modifiers::None, 'J' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord( std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'K' }, [](Window& window, int count) { window.move_selections(BufferCoord(-std::max(count,1), 0), true); } }, { { Key::Modifiers::None, 'K' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(-std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'L' }, [](Window& window, int count) { window.move_selections(BufferCoord(0, std::max(count,1)), true); } }, { { Key::Modifiers::None, 'L' }, [](Editor& editor, int count) { editor.move_selections(BufferCoord(0, std::max(count,1)), true); } },
{ { Key::Modifiers::None, 't' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, false)); } }, { { Key::Modifiers::None, 't' }, [](Editor& editor, int count) { editor.select(std::bind(select_to, _1, getch(), count, false)); } },
{ { Key::Modifiers::None, 'f' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true)); } }, { { Key::Modifiers::None, 'f' }, [](Editor& editor, int count) { editor.select(std::bind(select_to, _1, getch(), count, true)); } },
{ { Key::Modifiers::None, 'T' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, false), true); } }, { { Key::Modifiers::None, 'T' }, [](Editor& editor, int count) { editor.select(std::bind(select_to, _1, getch(), count, false), true); } },
{ { Key::Modifiers::None, 'F' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true), true); } }, { { Key::Modifiers::None, 'F' }, [](Editor& editor, int count) { editor.select(std::bind(select_to, _1, getch(), count, true), true); } },
{ { Key::Modifiers::None, 'd' }, do_erase }, { { Key::Modifiers::None, 'd' }, do_erase },
{ { Key::Modifiers::None, 'c' }, do_change }, { { Key::Modifiers::None, 'c' }, do_change },
{ { Key::Modifiers::None, 'i' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } }, { { Key::Modifiers::None, 'i' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::Insert); } },
{ { Key::Modifiers::None, 'I' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::InsertAtLineBegin); } }, { { Key::Modifiers::None, 'I' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::InsertAtLineBegin); } },
{ { Key::Modifiers::None, 'a' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Append); } }, { { Key::Modifiers::None, 'a' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::Append); } },
{ { Key::Modifiers::None, 'A' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::AppendAtLineEnd); } }, { { Key::Modifiers::None, 'A' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::AppendAtLineEnd); } },
{ { Key::Modifiers::None, 'o' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineBelow); } }, { { Key::Modifiers::None, 'o' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::OpenLineBelow); } },
{ { Key::Modifiers::None, 'O' }, [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } }, { { Key::Modifiers::None, 'O' }, [](Editor& editor, int count) { do_insert(editor, IncrementalInserter::Mode::OpenLineAbove); } },
{ { Key::Modifiers::None, 'g' }, do_go<false> }, { { Key::Modifiers::None, 'g' }, do_go<false> },
{ { Key::Modifiers::None, 'G' }, do_go<true> }, { { Key::Modifiers::None, 'G' }, do_go<true> },
@ -962,53 +969,53 @@ std::unordered_map<Key, std::function<void (Window& window, int count)>> keymap
{ { Key::Modifiers::None, '.' }, do_repeat_insert }, { { Key::Modifiers::None, '.' }, do_repeat_insert },
{ { Key::Modifiers::None, '%' }, [](Window& window, int count) { window.select([](const BufferIterator& cursor) { { Key::Modifiers::None, '%' }, [](Editor& editor, int count) { editor.select([](const BufferIterator& cursor)
{ return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } }, { return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } },
{ { Key::Modifiers::None, ':' }, [](Window& window, int count) { do_command(); } }, { { Key::Modifiers::None, ':' }, [](Editor& editor, int count) { do_command(); } },
{ { Key::Modifiers::None, '|' }, do_pipe }, { { Key::Modifiers::None, '|' }, do_pipe },
{ { Key::Modifiers::None, ' ' }, [](Window& window, int count) { if (count == 0) window.clear_selections(); { { Key::Modifiers::None, ' ' }, [](Editor& editor, int count) { if (count == 0) editor.clear_selections();
else window.keep_selection(count-1); } }, else editor.keep_selection(count-1); } },
{ { Key::Modifiers::None, 'w' }, [](Window& window, int count) { do { window.select(select_to_next_word); } while(--count > 0); } }, { { Key::Modifiers::None, 'w' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word); } while(--count > 0); } },
{ { Key::Modifiers::None, 'e' }, [](Window& window, int count) { do { window.select(select_to_next_word_end); } while(--count > 0); } }, { { Key::Modifiers::None, 'e' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word_end); } while(--count > 0); } },
{ { Key::Modifiers::None, 'b' }, [](Window& window, int count) { do { window.select(select_to_previous_word); } while(--count > 0); } }, { { Key::Modifiers::None, 'b' }, [](Editor& editor, int count) { do { editor.select(select_to_previous_word); } while(--count > 0); } },
{ { Key::Modifiers::None, 'W' }, [](Window& window, int count) { do { window.select(select_to_next_word, true); } while(--count > 0); } }, { { Key::Modifiers::None, 'W' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word, true); } while(--count > 0); } },
{ { Key::Modifiers::None, 'E' }, [](Window& window, int count) { do { window.select(select_to_next_word_end, true); } while(--count > 0); } }, { { Key::Modifiers::None, 'E' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word_end, true); } while(--count > 0); } },
{ { Key::Modifiers::None, 'B' }, [](Window& window, int count) { do { window.select(select_to_previous_word, true); } while(--count > 0); } }, { { Key::Modifiers::None, 'B' }, [](Editor& editor, int count) { do { editor.select(select_to_previous_word, true); } while(--count > 0); } },
{ { Key::Modifiers::None, 'x' }, [](Window& window, int count) { do { window.select(select_line, false); } while(--count > 0); } }, { { Key::Modifiers::None, 'x' }, [](Editor& editor, int count) { do { editor.select(select_line, false); } while(--count > 0); } },
{ { Key::Modifiers::None, 'X' }, [](Window& window, int count) { do { window.select(select_line, true); } while(--count > 0); } }, { { Key::Modifiers::None, 'X' }, [](Editor& editor, int count) { do { editor.select(select_line, true); } while(--count > 0); } },
{ { Key::Modifiers::None, 'm' }, [](Window& window, int count) { window.select(select_matching); } }, { { Key::Modifiers::None, 'm' }, [](Editor& editor, int count) { editor.select(select_matching); } },
{ { Key::Modifiers::None, 'M' }, [](Window& window, int count) { window.select(select_matching, true); } }, { { Key::Modifiers::None, 'M' }, [](Editor& editor, int count) { editor.select(select_matching, true); } },
{ { Key::Modifiers::None, '/' }, [](Window& window, int count) { do_search(window); } }, { { Key::Modifiers::None, '/' }, [](Editor& editor, int count) { do_search(editor); } },
{ { Key::Modifiers::None, 'n' }, [](Window& window, int count) { do_search_next(window); } }, { { Key::Modifiers::None, 'n' }, [](Editor& editor, int count) { do_search_next(editor); } },
{ { Key::Modifiers::None, 'u' }, [](Window& window, int count) { do { if (not window.undo()) { print_status("nothing left to undo"); break; } } while(--count > 0); } }, { { Key::Modifiers::None, 'u' }, [](Editor& editor, int count) { do { if (not editor.undo()) { print_status("nothing left to undo"); break; } } while(--count > 0); } },
{ { Key::Modifiers::None, 'U' }, [](Window& window, int count) { do { if (not window.redo()) { print_status("nothing left to redo"); break; } } while(--count > 0); } }, { { Key::Modifiers::None, 'U' }, [](Editor& editor, int count) { do { if (not editor.redo()) { print_status("nothing left to redo"); break; } } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'i' }, do_select_surrounding<true> }, { { Key::Modifiers::Alt, 'i' }, do_select_surrounding<true> },
{ { Key::Modifiers::Alt, 'a' }, do_select_surrounding<false> }, { { Key::Modifiers::Alt, 'a' }, do_select_surrounding<false> },
{ { Key::Modifiers::Alt, 't' }, [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false)); } }, { { Key::Modifiers::Alt, 't' }, [](Editor& editor, int count) { editor.select(std::bind(select_to_reverse, _1, getch(), count, false)); } },
{ { Key::Modifiers::Alt, 'f' }, [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true)); } }, { { Key::Modifiers::Alt, 'f' }, [](Editor& editor, int count) { editor.select(std::bind(select_to_reverse, _1, getch(), count, true)); } },
{ { Key::Modifiers::Alt, 'T' }, [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false), true); } }, { { Key::Modifiers::Alt, 'T' }, [](Editor& editor, int count) { editor.select(std::bind(select_to_reverse, _1, getch(), count, false), true); } },
{ { Key::Modifiers::Alt, 'F' }, [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true), true); } }, { { Key::Modifiers::Alt, 'F' }, [](Editor& editor, int count) { editor.select(std::bind(select_to_reverse, _1, getch(), count, true), true); } },
{ { Key::Modifiers::Alt, 'w' }, [](Window& window, int count) { do { window.select(select_to_next_WORD); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'w' }, [](Editor& editor, int count) { do { editor.select(select_to_next_WORD); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'e' }, [](Window& window, int count) { do { window.select(select_to_next_WORD_end); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'e' }, [](Editor& editor, int count) { do { editor.select(select_to_next_WORD_end); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'b' }, [](Window& window, int count) { do { window.select(select_to_previous_WORD); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'b' }, [](Editor& editor, int count) { do { editor.select(select_to_previous_WORD); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'W' }, [](Window& window, int count) { do { window.select(select_to_next_WORD, true); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'W' }, [](Editor& editor, int count) { do { editor.select(select_to_next_WORD, true); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'E' }, [](Window& window, int count) { do { window.select(select_to_next_WORD_end, true); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'E' }, [](Editor& editor, int count) { do { editor.select(select_to_next_WORD_end, true); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'B' }, [](Window& window, int count) { do { window.select(select_to_previous_WORD, true); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'B' }, [](Editor& editor, int count) { do { editor.select(select_to_previous_WORD, true); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'l' }, [](Window& window, int count) { do { window.select(select_to_eol, false); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'l' }, [](Editor& editor, int count) { do { editor.select(select_to_eol, false); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'L' }, [](Window& window, int count) { do { window.select(select_to_eol, true); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'L' }, [](Editor& editor, int count) { do { editor.select(select_to_eol, true); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'h' }, [](Window& window, int count) { do { window.select(select_to_eol_reverse, false); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'h' }, [](Editor& editor, int count) { do { editor.select(select_to_eol_reverse, false); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 'H' }, [](Window& window, int count) { do { window.select(select_to_eol_reverse, true); } while(--count > 0); } }, { { Key::Modifiers::Alt, 'H' }, [](Editor& editor, int count) { do { editor.select(select_to_eol_reverse, true); } while(--count > 0); } },
{ { Key::Modifiers::Alt, 's' }, do_split_regex }, { { Key::Modifiers::Alt, 's' }, do_split_regex },
{ { Key::Modifiers::Alt, 'j' }, do_join }, { { Key::Modifiers::Alt, 'j' }, do_join },
{ { Key::Modifiers::Alt, 'x' }, [](Window& window, int count) { window.multi_select(select_whole_lines); } }, { { Key::Modifiers::Alt, 'x' }, [](Editor& editor, int count) { editor.multi_select(select_whole_lines); } },
}; };
void exec_string(const CommandParameters& params, void exec_string(const CommandParameters& params,
@ -1048,11 +1055,8 @@ void exec_string(const CommandParameters& params,
return keys[pos++]; return keys[pos++];
}; };
std::unique_ptr<Window> temp_window; Editor standalone_editor(context.buffer());
if (not context.has_window()) Editor& editor = context.has_window() ? context.window() : standalone_editor;
temp_window = context.buffer().create_temporary_window();
Window& window = context.has_window() ? context.window() : *temp_window;
int count = 0; int count = 0;
while(pos < keys.size()) while(pos < keys.size())
@ -1065,7 +1069,7 @@ void exec_string(const CommandParameters& params,
{ {
auto it = keymap.find(key); auto it = keymap.find(key);
if (it != keymap.end()) if (it != keymap.end())
it->second(window, count); it->second(editor, count);
count = 0; count = 0;
} }
} }