[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] src: vi-mode: moving jumps to separate class
From: Michal Humpula <michal.humpula () hudrydum ! cz>
Date: 2014-06-30 20:09:04
Message-ID: E1X1hsu-0007ZD-7c () scm ! kde ! org
[Download RAW message or body]
Git commit baa070d8c83c815359cb2d64e9f8f8adc524499f by Michal Humpula.
Committed on 30/06/2014 at 18:37.
Pushed by michalhumpula into branch 'master'.
vi-mode: moving jumps to separate class
REVIEW: 119047
M +1 -0 src/CMakeLists.txt
A +135 -0 src/vimode/jumps.cpp [License: LGPL (v2+)]
A +58 -0 src/vimode/jumps.h [License: LGPL (v2+)]
M +4 -98 src/vimode/kateviinputmodemanager.cpp
M +3 -15 src/vimode/kateviinputmodemanager.h
M +3 -8 src/vimode/katevimodebase.cpp
M +0 -5 src/vimode/katevinormalmode.cpp
M +0 -2 src/vimode/katevinormalmode.h
http://commits.kde.org/ktexteditor/baa070d8c83c815359cb2d64e9f8f8adc524499f
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 44bc609..24c0a64 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -245,6 +245,7 @@ if (BUILD_VIMODE)
vimode/katevikeymapper.cpp
vimode/kateviinputmodeconfigtab.cpp
vimode/marks.cpp
+ vimode/jumps.cpp
)
endif()
diff --git a/src/vimode/jumps.cpp b/src/vimode/jumps.cpp
new file mode 100644
index 0000000..7a15097
--- /dev/null
+++ b/src/vimode/jumps.cpp
@@ -0,0 +1,135 @@
+/* This file is part of the KDE libraries
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "jumps.h"
+#include "katepartdebug.h"
+
+using namespace KateVi;
+
+Jumps::Jumps()
+{
+ m_jumps = new QList<Jump>;
+ m_current = m_jumps->begin();
+}
+
+Jumps::~Jumps()
+{
+ delete m_jumps;
+}
+
+void Jumps::add(const KTextEditor::Cursor &cursor)
+{
+ for (QList<Jump>::iterator iterator = m_jumps->begin();
+ iterator != m_jumps->end();
+ iterator++
+ )
+ {
+ if ((*iterator).line == cursor.line()) {
+ m_jumps->erase(iterator);
+ break;
+ }
+ }
+
+ Jump jump = {cursor.line(), cursor.column()};
+ m_jumps->push_back(jump);
+ m_current = m_jumps->end();
+
+ printJumpList();
+}
+
+KTextEditor::Cursor Jumps::next(const KTextEditor::Cursor &cursor)
+{
+ if (m_current == m_jumps->end()) {
+ return cursor;
+ }
+
+ Jump jump;
+
+ if (m_current + 1 != m_jumps->end()) {
+ jump = *(++m_current);
+ } else {
+ jump = *(m_current);
+ }
+
+ printJumpList();
+
+ return KTextEditor::Cursor(jump.line, jump.column);
+}
+
+KTextEditor::Cursor Jumps::prev(const KTextEditor::Cursor &cursor)
+{
+ if (m_current == m_jumps->end()) {
+ add(cursor);
+ m_current--;
+ }
+
+ if (m_current != m_jumps->begin()) {
+ m_current--;
+
+ printJumpList();
+ return KTextEditor::Cursor(m_current->line, m_current->column);
+ }
+
+ printJumpList();
+
+ return cursor;
+}
+
+void Jumps::printJumpList() const
+{
+ qCDebug(LOG_PART) << "Jump List";
+ for (QList<Jump>::iterator iter = m_jumps->begin();
+ iter != m_jumps->end();
+ iter++)
+ {
+ if (iter == m_current) {
+ qCDebug(LOG_PART) << (*iter).line << (*iter).column << "<< Current Jump";
+ } else {
+ qCDebug(LOG_PART) << (*iter).line << (*iter).column;
+ }
+ }
+
+ if (m_current == m_jumps->end()) {
+ qCDebug(LOG_PART) << " << Current Jump";
+ }
+}
+
+void Jumps::readSessionConfig(const KConfigGroup &config)
+{
+ // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
+ m_jumps->clear();
+ QStringList jumps = config.readEntry("JumpList", QStringList());
+
+ for (int i = 0; i + 1 < jumps.size(); i += 2) {
+ Jump jump = {jumps.at(i).toInt(), jumps.at(i + 1).toInt()};
+ m_jumps->push_back(jump);
+ }
+
+ m_current = m_jumps->end();
+ printJumpList();
+}
+
+void Jumps::writeSessionConfig(KConfigGroup &config) const
+{
+ // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
+ QStringList l;
+ Q_FOREACH(const Jump &jump, *m_jumps) {
+ l << QString::number(jump.line) << QString::number(jump.column);
+ }
+ config.writeEntry("JumpList", l);
+}
diff --git a/src/vimode/jumps.h b/src/vimode/jumps.h
new file mode 100644
index 0000000..5cb7c9a
--- /dev/null
+++ b/src/vimode/jumps.h
@@ -0,0 +1,58 @@
+/* This file is part of the KDE libraries
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KATEVI_JUMPS_H
+#define KATEVI_JUMPS_H
+
+#include <ktexteditor/cursor.h>
+
+#include <KConfigGroup>
+
+#include <QList>
+
+namespace KateVi {
+
+class Jumps
+{
+public:
+ explicit Jumps();
+ ~Jumps();
+
+ void add(const KTextEditor::Cursor &cursor);
+ KTextEditor::Cursor next(const KTextEditor::Cursor &cursor);
+ KTextEditor::Cursor prev(const KTextEditor::Cursor &cursor);
+
+ void writeSessionConfig(KConfigGroup &config) const;
+ void readSessionConfig(const KConfigGroup &config);
+
+private:
+ void printJumpList() const;
+
+private:
+ struct Jump {
+ int line;
+ int column;
+ };
+
+ QList<Jump> *m_jumps;
+ QList<Jump>::iterator m_current;
+};
+
+}
+
+#endif // KATEVI_JUMPS_H
diff --git a/src/vimode/kateviinputmodemanager.cpp b/src/vimode/kateviinputmodemanager.cpp
index 076f5c0..b01adb4 100644
--- a/src/vimode/kateviinputmodemanager.cpp
+++ b/src/vimode/kateviinputmodemanager.cpp
@@ -79,10 +79,9 @@ KateViInputModeManager::KateViInputModeManager(KateViInputMode *inputAdapter, KT
m_lastSearchCaseSensitive = false;
m_lastSearchPlacedCursorAtEndOfMatch = false;
- jump_list = new QList<KateViJump>;
- current_jump = jump_list->begin();
m_temporaryNormalMode = false;
+ m_jumps = new KateVi::Jumps();
m_marks = new KateVi::Marks(this);
// We have to do this outside of KateViNormalMode, as we don't want
@@ -97,7 +96,7 @@ KateViInputModeManager::~KateViInputModeManager()
delete m_viInsertMode;
delete m_viVisualMode;
delete m_viReplaceMode;
- delete jump_list;
+ delete m_jumps;
delete m_marks;
}
@@ -568,30 +567,13 @@ const QString KateViInputModeManager::getVerbatimKeys() const
void KateViInputModeManager::readSessionConfig(const KConfigGroup &config)
{
- // Reading jump list
- // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
- jump_list->clear();
- QStringList jumps = config.readEntry("JumpList", QStringList());
- for (int i = 0; i + 1 < jumps.size(); i += 2) {
- KateViJump jump = {jumps.at(i).toInt(), jumps.at(i + 1).toInt() };
- jump_list->push_back(jump);
- }
- current_jump = jump_list->end();
- PrintJumpList();
-
+ m_jumps->readSessionConfig(config);
m_marks->readSessionConfig(config);
}
void KateViInputModeManager::writeSessionConfig(KConfigGroup &config)
{
- // Writing Jump List
- // Format: jump1.line, jump1.column, jump2.line, jump2.column, jump3.line, ...
- QStringList l;
- for (int i = 0; i < jump_list->size(); i++) {
- l << QString::number(jump_list->at(i).line) << QString::number(jump_list->at(i).column);
- }
- config.writeEntry("JumpList", l);
-
+ m_jumps->writeSessionConfig(config);
m_marks->writeSessionConfig(config);
}
@@ -602,82 +584,6 @@ void KateViInputModeManager::reset()
}
}
-void KateViInputModeManager::addJump(Cursor cursor)
-{
- for (QList<KateViJump>::iterator iterator = jump_list->begin();
- iterator != jump_list->end();
- iterator ++) {
- if ((*iterator).line == cursor.line()) {
- jump_list->erase(iterator);
- break;
- }
- }
-
- KateViJump jump = { cursor.line(), cursor.column()};
- jump_list->push_back(jump);
- current_jump = jump_list->end();
-
- // DEBUG
- PrintJumpList();
-
-}
-
-Cursor KateViInputModeManager::getNextJump(Cursor cursor)
-{
- if (current_jump != jump_list->end()) {
- KateViJump jump;
- if (current_jump + 1 != jump_list->end()) {
- jump = *(++current_jump);
- } else {
- jump = *(current_jump);
- }
-
- cursor = Cursor(jump.line, jump.column);
- }
-
- // DEBUG
- PrintJumpList();
-
- return cursor;
-}
-
-Cursor KateViInputModeManager::getPrevJump(Cursor cursor)
-{
- if (current_jump == jump_list->end()) {
- addJump(cursor);
- current_jump--;
- }
-
- if (current_jump != jump_list->begin()) {
- KateViJump jump;
- jump = *(--current_jump);
- cursor = Cursor(jump.line, jump.column);
- }
-
- // DEBUG
- PrintJumpList();
-
- return cursor;
-}
-
-void KateViInputModeManager::PrintJumpList()
-{
- qCDebug(LOG_PART) << "Jump List";
- for (QList<KateViJump>::iterator iter = jump_list->begin();
- iter != jump_list->end();
- iter++) {
- if (iter == current_jump) {
- qCDebug(LOG_PART) << (*iter).line << (*iter).column << "<< Current Jump";
- } else {
- qCDebug(LOG_PART) << (*iter).line << (*iter).column;
- }
- }
- if (current_jump == jump_list->end()) {
- qCDebug(LOG_PART) << " << Current Jump";
- }
-
-}
-
KateViKeyMapper *KateViInputModeManager::keyMapper()
{
return m_keyMapperStack.top().data();
diff --git a/src/vimode/kateviinputmodemanager.h b/src/vimode/kateviinputmodemanager.h
index 64a1b6d..3ed6eff 100644
--- a/src/vimode/kateviinputmodemanager.h
+++ b/src/vimode/kateviinputmodemanager.h
@@ -32,6 +32,7 @@
#include <ktexteditor/view.h>
#include "marks.h"
+#include "jumps.h"
class KateViGlobal;
class KConfigGroup;
@@ -59,11 +60,6 @@ enum ViMode {
ReplaceMode
};
-struct KateViJump {
- int line;
- int column;
-};
-
namespace KTextEditor
{
class MovingCursor;
@@ -298,13 +294,8 @@ public:
void reset();
- // Jump Lists
- void addJump(KTextEditor::Cursor cursor);
- KTextEditor::Cursor getNextJump(KTextEditor::Cursor cursor);
- KTextEditor::Cursor getPrevJump(KTextEditor::Cursor cursor);
- void PrintJumpList();
-
inline KateVi::Marks *marks() { return m_marks; }
+ inline KateVi::Jumps *jumps() { return m_jumps; }
// session stuff
void readSessionConfig(const KConfigGroup &config);
@@ -394,11 +385,8 @@ private:
*/
bool m_temporaryNormalMode;
- // jump list
- QList<KateViJump> *jump_list;
- QList<KateViJump>::iterator current_jump;
-
KateVi::Marks *m_marks;
+ KateVi::Jumps *m_jumps;
};
#endif
diff --git a/src/vimode/katevimodebase.cpp b/src/vimode/katevimodebase.cpp
index 4ffd04b..153e475 100644
--- a/src/vimode/katevimodebase.cpp
+++ b/src/vimode/katevimodebase.cpp
@@ -954,19 +954,14 @@ void KateViModeBase::fillRegister(const QChar ®, const QString &text, Operati
m_viInputModeManager->viGlobal()->fillRegister(reg, text, flag);
}
-void KateViModeBase::addJump(KTextEditor::Cursor cursor)
-{
- m_viInputModeManager->addJump(cursor);
-}
-
KTextEditor::Cursor KateViModeBase::getNextJump(KTextEditor::Cursor cursor) const
{
- return m_viInputModeManager->getNextJump(cursor);
+ return m_viInputModeManager->jumps()->next(cursor);
}
KTextEditor::Cursor KateViModeBase::getPrevJump(KTextEditor::Cursor cursor) const
{
- return m_viInputModeManager->getPrevJump(cursor);
+ return m_viInputModeManager->jumps()->prev(cursor);
}
KateViRange KateViModeBase::goLineDown()
@@ -1505,7 +1500,7 @@ void KateViModeBase::goToPos(const KateViRange &r)
c.setColumn(r.endColumn);
if (r.jump) {
- m_viInputModeManager->addJump(m_view->cursorPosition());
+ m_viInputModeManager->jumps()->add(m_view->cursorPosition());
}
if (c.line() >= doc()->lines()) {
diff --git a/src/vimode/katevinormalmode.cpp b/src/vimode/katevinormalmode.cpp
index e60087b..8fa6f94 100644
--- a/src/vimode/katevinormalmode.cpp
+++ b/src/vimode/katevinormalmode.cpp
@@ -540,11 +540,6 @@ void KateViNormalMode::executeCommand(const KateViCommand *cmd)
}
}
-void KateViNormalMode::addCurrentPositionToJumpList()
-{
- m_viInputModeManager->addJump(m_view->cursorPosition());
-}
-
////////////////////////////////////////////////////////////////////////////////
// COMMANDS AND OPERATORS
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/vimode/katevinormalmode.h b/src/vimode/katevinormalmode.h
index bdd098c..0ca9a5d 100644
--- a/src/vimode/katevinormalmode.h
+++ b/src/vimode/katevinormalmode.h
@@ -289,8 +289,6 @@ public:
KateViRange textObjectAComma();
KateViRange textObjectInnerComma();
- void addCurrentPositionToJumpList();
-
virtual void reset();
void beginMonitoringDocumentChanges();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic