Window: empty_selections -> clear_selections

clear_selections also reset select_mode to Normal,
most editing operations now do a clear_selections.
This commit is contained in:
Maxime Coste 2011-10-05 14:24:52 +00:00
parent 4ce349fa02
commit ff730380ed
3 changed files with 10 additions and 6 deletions

View File

@ -314,6 +314,7 @@ void do_insert(Window& window, IncrementalInserter::Mode mode)
} }
draw_window(window); draw_window(window);
} }
window.clear_selections();
} }
void do_go(Window& window, int count) void do_go(Window& window, int count)
@ -447,18 +448,19 @@ void do_search_next(Window& window)
void do_yank(Window& window, int count) void do_yank(Window& window, int count)
{ {
RegisterManager::instance()['"'] = window.selection_content(); RegisterManager::instance()['"'] = window.selection_content();
window.clear_selections();
} }
void do_erase(Window& window, int count) void do_erase(Window& window, int count)
{ {
do_yank(window, 0); RegisterManager::instance()['"'] = window.selection_content();
window.erase(); window.erase();
window.empty_selections(); window.clear_selections();
} }
void do_change(Window& window, int count) void do_change(Window& window, int count)
{ {
do_yank(window, 0); RegisterManager::instance()['"'] = window.selection_content();
do_insert(window, IncrementalInserter::Mode::Change); do_insert(window, IncrementalInserter::Mode::Change);
} }
@ -469,6 +471,7 @@ void do_paste(Window& window, int count)
window.append(RegisterManager::instance()['"']); window.append(RegisterManager::instance()['"']);
else else
window.insert(RegisterManager::instance()['"']); window.insert(RegisterManager::instance()['"']);
window.clear_selections();
} }
std::unordered_map<char, std::function<void (Window& window, int count)>> keymap = std::unordered_map<char, std::function<void (Window& window, int count)>> keymap =
@ -502,7 +505,7 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } }, { return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } },
{ ':', [](Window& window, int count) { do_command(); } }, { ':', [](Window& window, int count) { do_command(); } },
{ ' ', [](Window& window, int count) { window.empty_selections(); } }, { ' ', [](Window& window, int count) { window.clear_selections(); } },
{ 'w', [](Window& window, int count) { do { window.select(select_to_next_word); } while(--count > 0); } }, { 'w', [](Window& window, int count) { do { window.select(select_to_next_word); } while(--count > 0); } },
{ 'e', [](Window& window, int count) { do { window.select(select_to_next_word_end); } while(--count > 0); } }, { 'e', [](Window& window, int count) { do { window.select(select_to_next_word_end); } while(--count > 0); } },
{ 'b', [](Window& window, int count) { do { window.select(select_to_previous_word); } while(--count > 0); } }, { 'b', [](Window& window, int count) { do { window.select(select_to_previous_word); } while(--count > 0); } },

View File

@ -222,13 +222,14 @@ WindowCoord Window::line_and_column_at(const BufferIterator& iterator) const
return buffer_to_window(m_buffer.line_and_column_at(iterator)); return buffer_to_window(m_buffer.line_and_column_at(iterator));
} }
void Window::empty_selections() void Window::clear_selections()
{ {
check_invariant(); check_invariant();
Selection sel = Selection(m_selections.back().last(), Selection sel = Selection(m_selections.back().last(),
m_selections.back().last()); m_selections.back().last());
m_selections.clear(); m_selections.clear();
m_selections.push_back(std::move(sel)); m_selections.push_back(std::move(sel));
m_select_mode = SelectMode::Normal;
} }
void Window::select(const Selector& selector) void Window::select(const Selector& selector)

View File

@ -70,7 +70,7 @@ public:
void move_cursor(const WindowCoord& offset); void move_cursor(const WindowCoord& offset);
void move_cursor_to(const WindowCoord& new_pos); void move_cursor_to(const WindowCoord& new_pos);
void empty_selections(); void clear_selections();
void select(const Selector& selector); void select(const Selector& selector);
BufferString selection_content() const; BufferString selection_content() const;