diff options
| author | Delapouite <delapouite@gmail.com> | 2017-11-13 08:34:02 +0100 |
|---|---|---|
| committer | Delapouite <delapouite@gmail.com> | 2017-11-13 08:38:43 +0100 |
| commit | a071e5b226b92316dcbd3e62bb89db6061ef031b (patch) | |
| tree | b4b4d1eb18b5ab7d6c24feb99ddc38ee75364e62 /src | |
| parent | b298e01390ceafbd8b800086f26307b6f28f6634 (diff) | |
Add count support to jumps (<c-o> and <c-i>). Add jumps tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/context.cc | 18 | ||||
| -rw-r--r-- | src/context.hh | 4 | ||||
| -rw-r--r-- | src/normal.cc | 7 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/context.cc b/src/context.cc index e3e20e0c..ef2a999f 100644 --- a/src/context.cc +++ b/src/context.cc @@ -86,12 +86,13 @@ void JumpList::push(SelectionList jump) 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 - 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(); context.print_status({ format("jumped to #{} ({})", m_current, m_jumps.size() - 1), @@ -101,14 +102,18 @@ const SelectionList& JumpList::forward(Context& context) 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(); if (m_current != m_jumps.size() and m_jumps[m_current] != current) { push(current); - SelectionList& res = m_jumps[--m_current]; + m_current -= count; + SelectionList& res = m_jumps[m_current]; res.update(); context.print_status({ format("jumped to #{} ({})", m_current, m_jumps.size() - 1), @@ -123,7 +128,8 @@ const SelectionList& JumpList::backward(Context& context) if (--m_current == 0) throw runtime_error("no previous jump"); } - SelectionList& res = m_jumps[--m_current]; + m_current -= count; + SelectionList& res = m_jumps[m_current]; res.update(); context.print_status({ format("jumped to #{} ({})", m_current, m_jumps.size() - 1), diff --git a/src/context.hh b/src/context.hh index 6c2a4641..754dfd77 100644 --- a/src/context.hh +++ b/src/context.hh @@ -20,8 +20,8 @@ class AliasRegistry; struct JumpList { void push(SelectionList jump); - const SelectionList& forward(Context& context); - const SelectionList& backward(Context& context); + const SelectionList& forward(Context& context, int count); + const SelectionList& backward(Context& context, int count); void forget_buffer(Buffer& buffer); friend bool operator==(const JumpList& lhs, const JumpList& rhs) diff --git a/src/normal.cc b/src/normal.cc index 483be93c..9a407ec1 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1403,11 +1403,12 @@ void replay_macro(Context& context, NormalParams params) } 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) ? - context.jump_list().forward(context) : - context.jump_list().backward(context); + context.jump_list().forward(context, count) : + context.jump_list().backward(context, count); Buffer* oldbuf = &context.buffer(); Buffer& buffer = const_cast<Buffer&>(jump.buffer()); |
