Merge remote-tracking branch 'Delapouite/jump-count'
This commit is contained in:
commit
5f5188a89c
|
@ -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),
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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());
|
||||||
|
|
5
test/normal/jump/backward-count/cmd
Normal file
5
test/normal/jump/backward-count/cmd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
3<c-o>
|
||||||
|
aend<esc>
|
3
test/normal/jump/backward-count/in
Normal file
3
test/normal/jump/backward-count/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/backward-count/out
Normal file
3
test/normal/jump/backward-count/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fooend
|
||||||
|
bar
|
||||||
|
qux
|
5
test/normal/jump/backward-invalid-count/cmd
Normal file
5
test/normal/jump/backward-invalid-count/cmd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
42<c-o>
|
||||||
|
aend<esc>
|
3
test/normal/jump/backward-invalid-count/in
Normal file
3
test/normal/jump/backward-invalid-count/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/backward-invalid-count/out
Normal file
3
test/normal/jump/backward-invalid-count/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
qux
|
5
test/normal/jump/backward/cmd
Normal file
5
test/normal/jump/backward/cmd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
<c-o><c-o><c-o>
|
||||||
|
aend<esc>
|
3
test/normal/jump/backward/in
Normal file
3
test/normal/jump/backward/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/backward/out
Normal file
3
test/normal/jump/backward/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fooend
|
||||||
|
bar
|
||||||
|
qux
|
6
test/normal/jump/forward-count/cmd
Normal file
6
test/normal/jump/forward-count/cmd
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
<c-o><c-o><c-o>
|
||||||
|
3<tab>
|
||||||
|
aend<esc>
|
3
test/normal/jump/forward-count/in
Normal file
3
test/normal/jump/forward-count/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/forward-count/out
Normal file
3
test/normal/jump/forward-count/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
quxend
|
6
test/normal/jump/forward-invalid-count/cmd
Normal file
6
test/normal/jump/forward-invalid-count/cmd
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
<c-o><c-o><c-o>
|
||||||
|
42<tab>
|
||||||
|
aend<esc>
|
3
test/normal/jump/forward-invalid-count/in
Normal file
3
test/normal/jump/forward-invalid-count/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/forward-invalid-count/out
Normal file
3
test/normal/jump/forward-invalid-count/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
qux
|
6
test/normal/jump/forward/cmd
Normal file
6
test/normal/jump/forward/cmd
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
gj
|
||||||
|
/bar<ret>
|
||||||
|
/qux<ret>
|
||||||
|
<c-o><c-o><c-o>
|
||||||
|
<tab><tab><tab>
|
||||||
|
aend<esc>
|
3
test/normal/jump/forward/in
Normal file
3
test/normal/jump/forward/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
%(foo)
|
||||||
|
bar
|
||||||
|
qux
|
3
test/normal/jump/forward/out
Normal file
3
test/normal/jump/forward/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
quxend
|
Loading…
Reference in New Issue
Block a user