moving no longer clears multiple selections

This commit is contained in:
Maxime Coste 2012-01-25 14:23:02 +00:00
parent 81138b224f
commit d1c29d2b78
3 changed files with 23 additions and 33 deletions

View File

@ -378,10 +378,10 @@ bool insert_char(Window& window, IncrementalInserter& inserter, const Key& key)
inserter.insert(std::string() + '\n');
break;
case 'd':
inserter.move_cursor({0, -1});
inserter.move_cursors({0, -1});
break;
case 'e':
inserter.move_cursor({0, 1});
inserter.move_cursors({0, 1});
break;
case 'g':
inserter.erase();
@ -859,7 +859,7 @@ void do_join(Window& window, int count)
window.multi_select(std::bind(select_all_matches, _1, "\n\\h*"));
window.replace(" ");
window.clear_selections();
window.move_cursor({0, -1});
window.move_selections({0, -1});
}
template<bool inside>
@ -888,15 +888,15 @@ void do_select_surrounding(Window& window, int count)
std::unordered_map<Key, std::function<void (Window& window, int count)>> keymap =
{
{ { Key::Modifiers::None, 'h' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(0, -std::max(count,1))); } },
{ { Key::Modifiers::None, 'j' }, [](Window& window, int count) { window.move_cursor(DisplayCoord( std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'k' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(-std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'l' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(0, std::max(count,1))); } },
{ { Key::Modifiers::None, 'h' }, [](Window& window, int count) { window.move_selections(DisplayCoord(0, -std::max(count,1))); } },
{ { Key::Modifiers::None, 'j' }, [](Window& window, int count) { window.move_selections(DisplayCoord( std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'k' }, [](Window& window, int count) { window.move_selections(DisplayCoord(-std::max(count,1), 0)); } },
{ { Key::Modifiers::None, 'l' }, [](Window& window, int count) { window.move_selections(DisplayCoord(0, std::max(count,1))); } },
{ { Key::Modifiers::None, 'H' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(0, -std::max(count,1)), true); } },
{ { Key::Modifiers::None, 'J' }, [](Window& window, int count) { window.move_cursor(DisplayCoord( std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'K' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(-std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'L' }, [](Window& window, int count) { window.move_cursor(DisplayCoord(0, std::max(count,1)), true); } },
{ { Key::Modifiers::None, 'H' }, [](Window& window, int count) { window.move_selections(DisplayCoord(0, -std::max(count,1)), true); } },
{ { Key::Modifiers::None, 'J' }, [](Window& window, int count) { window.move_selections(DisplayCoord( std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'K' }, [](Window& window, int count) { window.move_selections(DisplayCoord(-std::max(count,1), 0), true); } },
{ { Key::Modifiers::None, 'L' }, [](Window& window, int count) { window.move_selections(DisplayCoord(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, 'f' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true)); } },

View File

@ -258,17 +258,14 @@ void Window::select(const Selector& selector, bool append)
if (not append)
{
Selection sel = selector(selections().back().last());
selections().clear();
selections().push_back(std::move(sel));
for (auto& sel : selections())
sel = selector(sel.last());
}
else
{
for (auto& sel : selections())
{
sel.merge_with(selector(sel.last()));
}
}
scroll_to_keep_cursor_visible_ifn();
}
@ -303,23 +300,16 @@ BufferString Window::selection_content() const
selections().back().end());
}
void Window::move_cursor(const DisplayCoord& offset, bool append)
{
if (not append)
{
BufferCoord pos = m_buffer.line_and_column_at(cursor_iterator());
move_cursor_to(m_buffer.iterator_at(pos + BufferCoord(offset)));
}
else
void Window::move_selections(const DisplayCoord& offset, bool append)
{
for (auto& sel : selections())
{
BufferCoord pos = m_buffer.line_and_column_at(sel.last());
sel = Selection(sel.first(), m_buffer.iterator_at(pos + BufferCoord(offset)));
BufferIterator last = m_buffer.iterator_at(pos + BufferCoord(offset));
sel = Selection(append ? sel.first() : last, last);
}
scroll_to_keep_cursor_visible_ifn();
}
}
void Window::move_cursor_to(const BufferIterator& iterator)
{
@ -461,7 +451,7 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
IncrementalInserter::~IncrementalInserter()
{
move_cursor(DisplayCoord(0, -1));
move_cursors(DisplayCoord(0, -1));
m_window.push_selections();
m_window.hooks_manager().run_hook("InsertEnd", "", Context(m_window));
@ -505,7 +495,7 @@ void IncrementalInserter::erase()
m_window.scroll_to_keep_cursor_visible_ifn();
}
void IncrementalInserter::move_cursor(const DisplayCoord& offset)
void IncrementalInserter::move_cursors(const DisplayCoord& offset)
{
for (auto& sel : m_window.selections())
{

View File

@ -77,7 +77,7 @@ public:
BufferIterator iterator_at(const DisplayCoord& window_pos) const;
DisplayCoord line_and_column_at(const BufferIterator& iterator) const;
void move_cursor(const DisplayCoord& offset, bool append = false);
void move_selections(const DisplayCoord& offset, bool append = false);
void move_cursor_to(const BufferIterator& iterator);
void clear_selections();
@ -167,7 +167,7 @@ public:
void insert(const Window::String& string);
void insert_capture(size_t index);
void erase();
void move_cursor(const DisplayCoord& offset);
void move_cursors(const DisplayCoord& offset);
private:
void apply(Modification&& modification) const;