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
14namespace KTextEditor
15{
16class ViewPrivate;
17}
18class KateViewInternal;
19
20class QKeyEvent;
21
22namespace KateVi
23{
24class Motion;
25
26/**
27 * Commands for the vi insert mode
28 */
29enum BlockInsert { None, Prepend, Append, AppendEOL };
30
31class InsertViMode : public ModeBase
32{
33public:
34 explicit InsertViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal);
35 ~InsertViMode() override;
36
37 bool handleKeypress(const QKeyEvent *e) override;
38
39 bool commandInsertFromAbove();
40 bool commandInsertFromBelow();
41
42 bool commandDeleteWord();
43 bool commandDeleteLine();
44 bool commandNewLine();
45 bool commandDeleteCharBackward();
46
47 bool commandIndent();
48 bool commandUnindent();
49
50 bool commandToFirstCharacterInFile();
51 bool commandToLastCharacterInFile();
52
53 bool commandMoveOneWordLeft();
54 bool commandMoveOneWordRight();
55
56 bool commandCompleteNext();
57 bool commandCompletePrevious();
58
59 bool commandInsertContentOfRegister();
60 bool commandSwitchToNormalModeForJustOneCommand();
61
62 void setBlockPrependMode(Range blockRange);
63 void setBlockAppendMode(Range blockRange, BlockInsert b);
64
65 void setCount(int count)
66 {
67 m_count = count;
68 }
69 void setCountedRepeatsBeginOnNewLine(bool countedRepeatsBeginOnNewLine)
70 {
71 m_countedRepeatsBeginOnNewLine = countedRepeatsBeginOnNewLine;
72 }
73
74protected:
75 void leaveInsertMode(bool force = false);
76 void completionFinished();
77
78protected:
79 BlockInsert m_blockInsert;
80 unsigned int m_eolPos; // length of first line in eol mode before text is appended
81 Range m_blockRange;
82
83 QString m_keys;
84 bool m_waitingRegister;
85
86 unsigned int m_count;
87 bool m_countedRepeatsBeginOnNewLine;
88
89 bool m_isExecutingCompletion;
90 QString m_textInsertedByCompletion;
91 KTextEditor::Cursor m_textInsertedByCompletionEndPos;
92
93private:
94 KTEXTEDITOR_NO_EXPORT
95 void textInserted(KTextEditor::Document *document, KTextEditor::Range range);
96};
97}
98
99#endif /* KATEVI_INSERT_VI_MODE_H */
100

source code of ktexteditor/src/vimode/modes/insertvimode.h