1/*
2 SPDX-FileCopyrightText: KDE Developers
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "jumps.h"
8
9using namespace KateVi;
10
11void Jumps::add(const KTextEditor::Cursor cursor)
12{
13 for (auto iterator = m_jumps.begin(); iterator != m_jumps.end(); iterator++) {
14 if ((*iterator).line() == cursor.line()) {
15 m_jumps.erase(pos: iterator);
16 break;
17 }
18 }
19
20 m_jumps.push_back(t: cursor);
21 m_current = m_jumps.end();
22}
23
24KTextEditor::Cursor Jumps::next(const KTextEditor::Cursor cursor)
25{
26 if (m_current == m_jumps.end()) {
27 return cursor;
28 }
29
30 KTextEditor::Cursor jump;
31 if (m_current + 1 != m_jumps.end()) {
32 jump = *(++m_current);
33 } else {
34 jump = *(m_current);
35 }
36
37 return jump;
38}
39
40KTextEditor::Cursor Jumps::prev(const KTextEditor::Cursor cursor)
41{
42 if (m_current == m_jumps.end()) {
43 add(cursor);
44 m_current--;
45 }
46
47 if (m_current != m_jumps.begin()) {
48 m_current--;
49 return *m_current;
50 }
51
52 return cursor;
53}
54
55void Jumps::readSessionConfig(const KConfigGroup &config)
56{
57 // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
58 m_jumps.clear();
59 QStringList jumps = config.readEntry(key: "JumpList", aDefault: QStringList());
60
61 for (int i = 0; i + 1 < jumps.size(); i += 2) {
62 KTextEditor::Cursor jump = {jumps.at(i).toInt(), jumps.at(i: i + 1).toInt()};
63 m_jumps.push_back(t: jump);
64 }
65
66 m_current = m_jumps.end();
67}
68
69void Jumps::writeSessionConfig(KConfigGroup &config) const
70{
71 if (m_jumps.isEmpty()) {
72 return;
73 }
74 // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
75 QStringList l;
76 for (const auto &jump : m_jumps) {
77 l << QString::number(jump.line()) << QString::number(jump.column());
78 }
79 config.writeEntry(key: "JumpList", value: l);
80}
81

source code of ktexteditor/src/vimode/jumps.cpp