summaryrefslogtreecommitdiff
path: root/src/context.cc
diff options
context:
space:
mode:
authorDelapouite <delapouite@gmail.com>2017-11-13 08:34:02 +0100
committerDelapouite <delapouite@gmail.com>2017-11-13 08:38:43 +0100
commita071e5b226b92316dcbd3e62bb89db6061ef031b (patch)
treeb4b4d1eb18b5ab7d6c24feb99ddc38ee75364e62 /src/context.cc
parentb298e01390ceafbd8b800086f26307b6f28f6634 (diff)
Add count support to jumps (<c-o> and <c-i>). Add jumps tests
Diffstat (limited to 'src/context.cc')
-rw-r--r--src/context.cc18
1 files changed, 12 insertions, 6 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),