KTextEditor

modebase.h
1/*
2 SPDX-FileCopyrightText: 2008-2009 Erlend Hamberg <ehamberg@gmail.com>
3 SPDX-FileCopyrightText: 2009 Paul Gideon Dann <pdgiddie@gmail.com>
4 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
5 SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KATEVI_MODE_BASE_H
11#define KATEVI_MODE_BASE_H
12
13#include <ktexteditor/range.h>
14
15#include "kateview.h"
16#include <vimode/definitions.h>
17#include <vimode/range.h>
18
19class QKeyEvent;
20class QString;
22class KateViewInternal;
23namespace KTextEditor
24{
25class DocumentPrivate;
26class ViewPrivate;
27class Message;
28}
29
30namespace KateVi
31{
32class InputModeManager;
33
34enum Direction { Up, Down, Left, Right, Next, Prev };
35
36class ModeBase : public QObject
37{
38public:
39 ModeBase() = default;
40 ~ModeBase() override = default;
41
42 /**
43 * @return normal mode command accumulated so far
44 */
45 QString getVerbatimKeys() const;
46 virtual bool handleKeypress(const QKeyEvent *e) = 0;
47
48 void setCount(unsigned int count)
49 {
50 m_count = count;
51 }
52 void setRegister(QChar reg)
53 {
54 m_register = reg;
55 }
56
57 void error(const QString &errorMsg);
58 void message(const QString &msg);
59
60 Range motionFindNext();
61 Range motionFindPrev();
62
63 virtual void goToPos(const Range &r);
64 int getCount() const;
65
66protected:
67 // helper methods
68 void yankToClipBoard(QChar chosen_register, const QString &text);
69 bool deleteRange(Range &r, OperationMode mode = LineWise, bool addToRegister = true);
70 const QString getRange(Range &r, OperationMode mode = LineWise) const;
71 const QString getLine(int line = -1) const;
72 const QChar getCharUnderCursor() const;
73 const QString getWordUnderCursor() const;
74 const KTextEditor::Range getWordRangeUnderCursor() const;
75 KTextEditor::Cursor findNextWordStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
76 KTextEditor::Cursor findNextWORDStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
77 KTextEditor::Cursor findPrevWordStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
78 KTextEditor::Cursor findPrevWORDStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
79 KTextEditor::Cursor findPrevWordEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
80 KTextEditor::Cursor findPrevWORDEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
81 KTextEditor::Cursor findWordEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
82 KTextEditor::Cursor findWORDEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
83
84 Range findSurroundingBrackets(const QChar &c1, const QChar &c2, bool inner, const QChar &nested1, const QChar &nested2) const;
85
86 Range findSurrounding(const QRegularExpression &c1, const QRegularExpression &c2, bool inner = false) const;
87 Range findSurroundingQuotes(const QChar &c, bool inner = false) const;
88
89 int findLineStartingWitchChar(const QChar &c, int count, bool forward = true) const;
90 void updateCursor(const KTextEditor::Cursor c) const;
91 static const QChar getCharAtVirtualColumn(const QString &line, int virtualColumn, int tabWidht);
92
93 void addToNumberUnderCursor(int count);
94
95 Range goLineUp();
96 Range goLineDown();
97 Range goLineUpDown(int lines);
98 Range goVisualLineUpDown(int lines);
99
100 unsigned int linesDisplayed() const;
101 void scrollViewLines(int l);
102
103 bool isCounted() const
104 {
105 return m_iscounted;
106 }
107
108 bool startNormalMode();
109 bool startInsertMode();
110 bool startVisualMode();
111 bool startVisualLineMode();
112 bool startVisualBlockMode();
113 bool startReplaceMode();
114
115 QChar getChosenRegister(const QChar &defaultReg) const;
116 QString getRegisterContent(const QChar &reg);
117 OperationMode getRegisterFlag(const QChar &reg) const;
118 void fillRegister(const QChar &reg, const QString &text, OperationMode flag = CharWise);
119
120 void switchView(Direction direction = Next);
121
122 KTextEditor::Cursor getNextJump(KTextEditor::Cursor) const;
123 KTextEditor::Cursor getPrevJump(KTextEditor::Cursor) const;
124
125 inline KTextEditor::DocumentPrivate *doc() const
126 {
127 return m_view->doc();
128 }
129
130protected:
131 QChar m_register;
132
133 Range m_commandRange;
134 unsigned int m_count = 0;
135 int m_oneTimeCountOverride = -1;
136 bool m_iscounted = false;
137
138 QString m_extraWordCharacters;
139 QString m_keysVerbatim;
140
141 int m_stickyColumn = -1;
142 bool m_lastMotionWasVisualLineUpOrDown;
143 bool m_currentMotionWasVisualLineUpOrDown;
144
145 KTextEditor::ViewPrivate *m_view;
146 KateViewInternal *m_viewInternal;
147 InputModeManager *m_viInputModeManager;
148
149 // info message of vi mode
150 QPointer<KTextEditor::Message> m_infoMessage;
151};
152}
153
154#endif
The Cursor represents a position in a Document.
Definition cursor.h:75
An object representing a section of text, from one Cursor to another.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.