File indexing completed on 2024-05-12 11:58:31
0001 /* 0002 SPDX-FileCopyrightText: 2008-2011 Erlend Hamberg <ehamberg@gmail.com> 0003 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> 0004 SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KATEVI_INSERT_VI_MODE_H 0010 #define KATEVI_INSERT_VI_MODE_H 0011 0012 #include <ktexteditor_export.h> 0013 #include <vimode/modes/modebase.h> 0014 0015 namespace KTextEditor 0016 { 0017 class ViewPrivate; 0018 } 0019 class KateViewInternal; 0020 0021 class QKeyEvent; 0022 0023 namespace KateVi 0024 { 0025 class Motion; 0026 0027 /** 0028 * Commands for the vi insert mode 0029 */ 0030 enum BlockInsert { None, Prepend, Append, AppendEOL }; 0031 0032 class KTEXTEDITOR_EXPORT InsertViMode : public ModeBase 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 explicit InsertViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); 0038 ~InsertViMode() override; 0039 0040 bool handleKeypress(const QKeyEvent *e) override; 0041 0042 bool commandInsertFromAbove(); 0043 bool commandInsertFromBelow(); 0044 0045 bool commandDeleteWord(); 0046 bool commandDeleteLine(); 0047 bool commandNewLine(); 0048 bool commandDeleteCharBackward(); 0049 0050 bool commandIndent(); 0051 bool commandUnindent(); 0052 0053 bool commandToFirstCharacterInFile(); 0054 bool commandToLastCharacterInFile(); 0055 0056 bool commandMoveOneWordLeft(); 0057 bool commandMoveOneWordRight(); 0058 0059 bool commandCompleteNext(); 0060 bool commandCompletePrevious(); 0061 0062 bool commandInsertContentOfRegister(); 0063 bool commandSwitchToNormalModeForJustOneCommand(); 0064 0065 void setBlockPrependMode(Range blockRange); 0066 void setBlockAppendMode(Range blockRange, BlockInsert b); 0067 0068 void setCount(int count) 0069 { 0070 m_count = count; 0071 } 0072 void setCountedRepeatsBeginOnNewLine(bool countedRepeatsBeginOnNewLine) 0073 { 0074 m_countedRepeatsBeginOnNewLine = countedRepeatsBeginOnNewLine; 0075 } 0076 0077 protected: 0078 void leaveInsertMode(bool force = false); 0079 void completionFinished(); 0080 0081 protected: 0082 BlockInsert m_blockInsert; 0083 unsigned int m_eolPos; // length of first line in eol mode before text is appended 0084 Range m_blockRange; 0085 0086 QString m_keys; 0087 bool m_waitingRegister; 0088 0089 unsigned int m_count; 0090 bool m_countedRepeatsBeginOnNewLine; 0091 0092 bool m_isExecutingCompletion; 0093 QString m_textInsertedByCompletion; 0094 KTextEditor::Cursor m_textInsertedByCompletionEndPos; 0095 0096 private Q_SLOTS: 0097 void textInserted(KTextEditor::Document *document, KTextEditor::Range range); 0098 }; 0099 0100 } 0101 0102 #endif /* KATEVI_INSERT_VI_MODE_H */