diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-11-12 19:59:25 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-11-12 19:59:25 +0100 |
| commit | 801f4e740c2de6676d0f9fa41c58e41adfa99c8f (patch) | |
| tree | 9efa7cb1eeec5ebb4ce118be380c60feeacf90d4 /src/context.hh | |
| parent | 41b5336296d9259d34c7e9a1b30b963fa1d7a5f2 (diff) | |
Add jump list support to context
jump forward is bound to ctrl-i
jump backward is bound to ctrl-o
switch buffers or jumping somewhere in the buffer push the current
position to the jump list.
when a buffer is deleted, all entries referencing it in jump lists
are erased.
Diffstat (limited to 'src/context.hh')
| -rw-r--r-- | src/context.hh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/context.hh b/src/context.hh index 0568c6c4..844b4d04 100644 --- a/src/context.hh +++ b/src/context.hh @@ -100,6 +100,62 @@ struct Context using Insertion = std::pair<InsertMode, std::vector<Key>>; Insertion& last_insert() { return m_last_insert; } + using Jump = std::pair<safe_ptr<Buffer>, BufferCoord>; + void push_jump() + { + Jump jump{safe_ptr<Buffer>{&buffer()}, + editor().selections().back().last().coord()}; + if (m_current_jump != m_jump_list.end()) + { + m_jump_list.erase(m_current_jump+1, m_jump_list.end()); + if (*m_current_jump == jump) + return; + } + + m_jump_list.push_back(jump); + m_current_jump = m_jump_list.end(); + } + + Jump jump_forward() + { + if (m_current_jump != m_jump_list.end() and + m_current_jump + 1 != m_jump_list.end()) + return *++m_current_jump; + throw runtime_error("no next jump"); + } + + Jump jump_backward() + { + if (m_current_jump != m_jump_list.begin()) + { + if (m_current_jump == m_jump_list.end()) + { + push_jump(); + --m_current_jump; + } + return *--m_current_jump; + } + throw runtime_error("no previous jump"); + } + + void forget_jumps_to_buffer(Buffer& buffer) + { + for (auto it = m_jump_list.begin(); it != m_jump_list.end();) + { + if (it->first == &buffer) + { + if (it < m_current_jump) + --m_current_jump; + else if (it == m_current_jump) + m_current_jump = m_jump_list.end(); + + it = m_jump_list.erase(it); + } + else + ++it; + } + } + int& numeric_param() { return m_numeric_param; } private: safe_ptr<Editor> m_editor; @@ -108,6 +164,10 @@ private: Insertion m_last_insert = {InsertMode::Insert, {}}; int m_numeric_param = 0; + + using JumpList = std::vector<Jump>; + JumpList m_jump_list; + JumpList::iterator m_current_jump = m_jump_list.begin(); }; } |
