Merge remote-tracking branch 'Delapouite/jump-count'

This commit is contained in:
Maxime Coste 2017-11-13 16:37:24 +08:00
commit 5f5188a89c
21 changed files with 87 additions and 11 deletions

View File

@ -86,12 +86,13 @@ void JumpList::push(SelectionList jump)
m_current = m_jumps.size(); m_current = m_jumps.size();
} }
const SelectionList& JumpList::forward(Context& context) const SelectionList& JumpList::forward(Context& context, int count)
{ {
if (m_current != m_jumps.size() and if (m_current != m_jumps.size() and
m_current + 1 != m_jumps.size()) m_current + count < m_jumps.size())
{ {
SelectionList& res = m_jumps[++m_current]; m_current += count;
SelectionList& res = m_jumps[m_current];
res.update(); res.update();
context.print_status({ format("jumped to #{} ({})", context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1), m_current, m_jumps.size() - 1),
@ -101,14 +102,18 @@ const SelectionList& JumpList::forward(Context& context)
throw runtime_error("no next jump"); throw runtime_error("no next jump");
} }
const SelectionList& JumpList::backward(Context& context) const SelectionList& JumpList::backward(Context& context, int count)
{ {
if ((int)m_current - count < 0)
throw runtime_error("no previous jump");
const SelectionList& current = context.selections(); const SelectionList& current = context.selections();
if (m_current != m_jumps.size() and if (m_current != m_jumps.size() and
m_jumps[m_current] != current) m_jumps[m_current] != current)
{ {
push(current); push(current);
SelectionList& res = m_jumps[--m_current]; m_current -= count;
SelectionList& res = m_jumps[m_current];
res.update(); res.update();
context.print_status({ format("jumped to #{} ({})", context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1), m_current, m_jumps.size() - 1),
@ -123,7 +128,8 @@ const SelectionList& JumpList::backward(Context& context)
if (--m_current == 0) if (--m_current == 0)
throw runtime_error("no previous jump"); throw runtime_error("no previous jump");
} }
SelectionList& res = m_jumps[--m_current]; m_current -= count;
SelectionList& res = m_jumps[m_current];
res.update(); res.update();
context.print_status({ format("jumped to #{} ({})", context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1), m_current, m_jumps.size() - 1),

View File

@ -20,8 +20,8 @@ class AliasRegistry;
struct JumpList struct JumpList
{ {
void push(SelectionList jump); void push(SelectionList jump);
const SelectionList& forward(Context& context); const SelectionList& forward(Context& context, int count);
const SelectionList& backward(Context& context); const SelectionList& backward(Context& context, int count);
void forget_buffer(Buffer& buffer); void forget_buffer(Buffer& buffer);
friend bool operator==(const JumpList& lhs, const JumpList& rhs) friend bool operator==(const JumpList& lhs, const JumpList& rhs)

View File

@ -1403,11 +1403,12 @@ void replay_macro(Context& context, NormalParams params)
} }
template<Direction direction> template<Direction direction>
void jump(Context& context, NormalParams) void jump(Context& context, NormalParams params)
{ {
const int count = std::max(1, params.count);
auto jump = (direction == Forward) ? auto jump = (direction == Forward) ?
context.jump_list().forward(context) : context.jump_list().forward(context, count) :
context.jump_list().backward(context); context.jump_list().backward(context, count);
Buffer* oldbuf = &context.buffer(); Buffer* oldbuf = &context.buffer();
Buffer& buffer = const_cast<Buffer&>(jump.buffer()); Buffer& buffer = const_cast<Buffer&>(jump.buffer());

View File

@ -0,0 +1,5 @@
gj
/bar<ret>
/qux<ret>
3<c-o>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
fooend
bar
qux

View File

@ -0,0 +1,5 @@
gj
/bar<ret>
/qux<ret>
42<c-o>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
foo
bar
qux

View File

@ -0,0 +1,5 @@
gj
/bar<ret>
/qux<ret>
<c-o><c-o><c-o>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
fooend
bar
qux

View File

@ -0,0 +1,6 @@
gj
/bar<ret>
/qux<ret>
<c-o><c-o><c-o>
3<tab>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
foo
bar
quxend

View File

@ -0,0 +1,6 @@
gj
/bar<ret>
/qux<ret>
<c-o><c-o><c-o>
42<tab>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
foo
bar
qux

View File

@ -0,0 +1,6 @@
gj
/bar<ret>
/qux<ret>
<c-o><c-o><c-o>
<tab><tab><tab>
aend<esc>

View File

@ -0,0 +1,3 @@
%(foo)
bar
qux

View File

@ -0,0 +1,3 @@
foo
bar
quxend