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 {
35 Up,
36 Down,
37 Left,
38 Right,
39 Next,
40 Prev
41};
42
43class ModeBase : public QObject
44{
45public:
46 ModeBase() = default;
47 ~ModeBase() override = default;
48
49 /**
50 * @return normal mode command accumulated so far
51 */
52 QString getVerbatimKeys() const;
53 virtual bool handleKeypress(const QKeyEvent *e) = 0;
54
55 void setCount(unsigned int count)
56 {
57 m_count = count;
58 }
59 void setRegister(QChar reg)
60 {
61 m_register = reg;
62 }
63
64 void error(const QString &errorMsg);
65 void message(const QString &msg);
66
67 Range motionFindNext();
68 Range motionFindPrev();
69
70 virtual void goToPos(const Range &r);
71 int getCount() const;
72
73protected:
74 // helper methods
75 void yankToClipBoard(QChar chosen_register, const QString &text);
76 bool deleteRange(Range &r, OperationMode mode = LineWise, bool addToRegister = true);
77 const QString getRange(Range &r, OperationMode mode = LineWise) const;
78 const QString getLine(int line = -1) const;
79 const QChar getCharUnderCursor() const;
80 const QString getWordUnderCursor() const;
81 const KTextEditor::Range getWordRangeUnderCursor() const;
82 KTextEditor::Cursor findNextWordStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
83 KTextEditor::Cursor findNextWORDStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
84 KTextEditor::Cursor findPrevWordStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
85 KTextEditor::Cursor findPrevWORDStart(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
86 KTextEditor::Cursor findPrevWordEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
87 KTextEditor::Cursor findPrevWORDEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
88 KTextEditor::Cursor findWordEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
89 KTextEditor::Cursor findWORDEnd(int fromLine, int fromColumn, bool onlyCurrentLine = false) const;
90
91 Range findSurroundingBrackets(const QChar &c1, const QChar &c2, bool inner, const QChar &nested1, const QChar &nested2) const;
92
93 Range findSurrounding(const QRegularExpression &c1, const QRegularExpression &c2, bool inner = false) const;
94 Range findSurroundingQuotes(const QChar &c, bool inner = false) const;
95
96 int findLineStartingWitchChar(const QChar &c, int count, bool forward = true) const;
97 void updateCursor(const KTextEditor::Cursor c) const;
98 static const QChar getCharAtVirtualColumn(const QString &line, int virtualColumn, int tabWidht);
99
100 void addToNumberUnderCursor(int count);
101
102 Range goLineUp();
103 Range goLineDown();
104 Range goLineUpDown(int lines);
105 Range goVisualLineUpDown(int lines);
106
107 unsigned int linesDisplayed() const;
108 void scrollViewLines(int l);
109
110 bool isCounted() const
111 {
112 return m_iscounted;
113 }
114
115 bool startNormalMode();
116 bool startInsertMode();
117 bool startVisualMode();
118 bool startVisualLineMode();
119 bool startVisualBlockMode();
120 bool startReplaceMode();
121
122 QChar getChosenRegister(const QChar &defaultReg) const;
123 QString getRegisterContent(const QChar &reg);
124 OperationMode getRegisterFlag(const QChar &reg) const;
125 void fillRegister(const QChar &reg, const QString &text, OperationMode flag = CharWise);
126
127 void switchView(Direction direction = Next);
128
129 KTextEditor::Cursor getNextJump(KTextEditor::Cursor) const;
130 KTextEditor::Cursor getPrevJump(KTextEditor::Cursor) const;
131
132 inline KTextEditor::DocumentPrivate *doc() const
133 {
134 return m_view->doc();
135 }
136
137protected:
138 QChar m_register;
139
140 Range m_commandRange;
141 unsigned int m_count = 0;
142 int m_oneTimeCountOverride = -1;
143 bool m_iscounted = false;
144
145 QString m_extraWordCharacters;
146 QString m_keysVerbatim;
147
148 int m_stickyColumn = -1;
149 bool m_lastMotionWasVisualLineUpOrDown;
150 bool m_currentMotionWasVisualLineUpOrDown;
151
152 KTextEditor::ViewPrivate *m_view;
153 KateViewInternal *m_viewInternal;
154 InputModeManager *m_viInputModeManager;
155
156 // info message of vi mode
157 QPointer<KTextEditor::Message> m_infoMessage;
158};
159}
160
161#endif
Backend of KTextEditor::Document related public KTextEditor interfaces.
This class holds a Message to display in Views.
Definition message.h:94
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-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:55:25 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.