1 | /* |
2 | SPDX-FileCopyrightText: 2008-2011 Erlend Hamberg <ehamberg@gmail.com> |
3 | SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> |
4 | SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KATEVI_INSERT_VI_MODE_H |
10 | #define KATEVI_INSERT_VI_MODE_H |
11 | |
12 | #include <vimode/modes/modebase.h> |
13 | |
14 | namespace KTextEditor |
15 | { |
16 | class ViewPrivate; |
17 | } |
18 | class KateViewInternal; |
19 | |
20 | class QKeyEvent; |
21 | |
22 | namespace KateVi |
23 | { |
24 | class Motion; |
25 | |
26 | /** |
27 | * Commands for the vi insert mode |
28 | */ |
29 | enum BlockInsert { |
30 | None, |
31 | Prepend, |
32 | Append, |
33 | AppendEOL |
34 | }; |
35 | |
36 | class InsertViMode : public ModeBase |
37 | { |
38 | public: |
39 | explicit InsertViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); |
40 | ~InsertViMode() override; |
41 | |
42 | bool handleKeypress(const QKeyEvent *e) override; |
43 | |
44 | bool commandInsertFromAbove(); |
45 | bool commandInsertFromBelow(); |
46 | |
47 | bool commandDeleteWord(); |
48 | bool commandDeleteLine(); |
49 | bool commandNewLine(); |
50 | bool commandDeleteCharBackward(); |
51 | |
52 | bool commandIndent(); |
53 | bool commandUnindent(); |
54 | |
55 | bool commandToFirstCharacterInFile(); |
56 | bool commandToLastCharacterInFile(); |
57 | |
58 | bool commandMoveOneWordLeft(); |
59 | bool commandMoveOneWordRight(); |
60 | |
61 | bool commandCompleteNext(); |
62 | bool commandCompletePrevious(); |
63 | |
64 | bool commandInsertContentOfRegister(); |
65 | bool commandSwitchToNormalModeForJustOneCommand(); |
66 | |
67 | void setBlockPrependMode(Range blockRange); |
68 | void setBlockAppendMode(Range blockRange, BlockInsert b); |
69 | |
70 | void setCount(int count) |
71 | { |
72 | m_count = count; |
73 | } |
74 | void setCountedRepeatsBeginOnNewLine(bool countedRepeatsBeginOnNewLine) |
75 | { |
76 | m_countedRepeatsBeginOnNewLine = countedRepeatsBeginOnNewLine; |
77 | } |
78 | |
79 | protected: |
80 | void leaveInsertMode(bool force = false); |
81 | void completionFinished(); |
82 | |
83 | protected: |
84 | BlockInsert m_blockInsert; |
85 | unsigned int m_eolPos; // length of first line in eol mode before text is appended |
86 | Range m_blockRange; |
87 | |
88 | QString m_keys; |
89 | bool m_waitingRegister; |
90 | |
91 | unsigned int m_count; |
92 | bool m_countedRepeatsBeginOnNewLine; |
93 | |
94 | bool m_isExecutingCompletion; |
95 | QString m_textInsertedByCompletion; |
96 | KTextEditor::Cursor m_textInsertedByCompletionEndPos; |
97 | |
98 | private: |
99 | KTEXTEDITOR_NO_EXPORT |
100 | void textInserted(KTextEditor::Document *document, KTextEditor::Range range); |
101 | }; |
102 | } |
103 | |
104 | #endif /* KATEVI_INSERT_VI_MODE_H */ |
105 | |