KTextEditor

jumps.cpp
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(iterator);
16 break;
17 }
18 }
19
20 m_jumps.push_back(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
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("JumpList", QStringList());
60
61 for (int i = 0; i + 1 < jumps.size(); i += 2) {
62 KTextEditor::Cursor jump = {jumps.at(i).toInt(), jumps.at(i + 1).toInt()};
63 m_jumps.push_back(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, ...
76 for (const auto &jump : m_jumps) {
77 l << QString::number(jump.line()) << QString::number(jump.column());
78 }
79 config.writeEntry("JumpList", l);
80}
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
The Cursor represents a position in a Document.
Definition cursor.h:75
constexpr int column() const noexcept
Retrieve the column on which this cursor is situated.
Definition cursor.h:192
constexpr int line() const noexcept
Retrieve the line on which this cursor is situated.
Definition cursor.h:174
const_reference at(qsizetype i) const const
iterator begin()
void clear()
iterator end()
iterator erase(const_iterator begin, const_iterator end)
bool isEmpty() const const
void push_back(parameter_type value)
qsizetype size() const const
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.