moving no longer clears multiple selections
This commit is contained in:
parent
81138b224f
commit
d1c29d2b78
22
src/main.cc
22
src/main.cc
|
@ -378,10 +378,10 @@ bool insert_char(Window& window, IncrementalInserter& inserter, const Key& key)
|
||||||
inserter.insert(std::string() + '\n');
|
inserter.insert(std::string() + '\n');
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
inserter.move_cursor({0, -1});
|
inserter.move_cursors({0, -1});
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
inserter.move_cursor({0, 1});
|
inserter.move_cursors({0, 1});
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
inserter.erase();
|
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.multi_select(std::bind(select_all_matches, _1, "\n\\h*"));
|
||||||
window.replace(" ");
|
window.replace(" ");
|
||||||
window.clear_selections();
|
window.clear_selections();
|
||||||
window.move_cursor({0, -1});
|
window.move_selections({0, -1});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool inside>
|
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 =
|
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, 'h' }, [](Window& window, int count) { window.move_selections(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, 'j' }, [](Window& window, int count) { window.move_selections(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, 'k' }, [](Window& window, int count) { window.move_selections(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, '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, '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_cursor(DisplayCoord( std::max(count,1), 0), 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_cursor(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_cursor(DisplayCoord(0, std::max(count,1)), 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, '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)); } },
|
{ { Key::Modifiers::None, 'f' }, [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true)); } },
|
||||||
|
|
|
@ -258,17 +258,14 @@ void Window::select(const Selector& selector, bool append)
|
||||||
|
|
||||||
if (not append)
|
if (not append)
|
||||||
{
|
{
|
||||||
Selection sel = selector(selections().back().last());
|
for (auto& sel : selections())
|
||||||
selections().clear();
|
sel = selector(sel.last());
|
||||||
selections().push_back(std::move(sel));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (auto& sel : selections())
|
for (auto& sel : selections())
|
||||||
{
|
|
||||||
sel.merge_with(selector(sel.last()));
|
sel.merge_with(selector(sel.last()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
scroll_to_keep_cursor_visible_ifn();
|
scroll_to_keep_cursor_visible_ifn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,22 +300,15 @@ BufferString Window::selection_content() const
|
||||||
selections().back().end());
|
selections().back().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::move_cursor(const DisplayCoord& offset, bool append)
|
void Window::move_selections(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
|
|
||||||
{
|
|
||||||
for (auto& sel : selections())
|
for (auto& sel : selections())
|
||||||
{
|
{
|
||||||
BufferCoord pos = m_buffer.line_and_column_at(sel.last());
|
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();
|
scroll_to_keep_cursor_visible_ifn();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::move_cursor_to(const BufferIterator& iterator)
|
void Window::move_cursor_to(const BufferIterator& iterator)
|
||||||
|
@ -461,7 +451,7 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
|
||||||
|
|
||||||
IncrementalInserter::~IncrementalInserter()
|
IncrementalInserter::~IncrementalInserter()
|
||||||
{
|
{
|
||||||
move_cursor(DisplayCoord(0, -1));
|
move_cursors(DisplayCoord(0, -1));
|
||||||
|
|
||||||
m_window.push_selections();
|
m_window.push_selections();
|
||||||
m_window.hooks_manager().run_hook("InsertEnd", "", Context(m_window));
|
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();
|
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())
|
for (auto& sel : m_window.selections())
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
BufferIterator iterator_at(const DisplayCoord& window_pos) const;
|
BufferIterator iterator_at(const DisplayCoord& window_pos) const;
|
||||||
DisplayCoord line_and_column_at(const BufferIterator& iterator) 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 move_cursor_to(const BufferIterator& iterator);
|
||||||
|
|
||||||
void clear_selections();
|
void clear_selections();
|
||||||
|
@ -167,7 +167,7 @@ public:
|
||||||
void insert(const Window::String& string);
|
void insert(const Window::String& string);
|
||||||
void insert_capture(size_t index);
|
void insert_capture(size_t index);
|
||||||
void erase();
|
void erase();
|
||||||
void move_cursor(const DisplayCoord& offset);
|
void move_cursors(const DisplayCoord& offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void apply(Modification&& modification) const;
|
void apply(Modification&& modification) const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user