File indexing completed on 2024-04-28 03:58:06
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 <vimode/modes/modebase.h> 0013 0014 namespace KTextEditor 0015 { 0016 class ViewPrivate; 0017 } 0018 class KateViewInternal; 0019 0020 class QKeyEvent; 0021 0022 namespace KateVi 0023 { 0024 class Motion; 0025 0026 /** 0027 * Commands for the vi insert mode 0028 */ 0029 enum BlockInsert { None, Prepend, Append, AppendEOL }; 0030 0031 class InsertViMode : public ModeBase 0032 { 0033 public: 0034 explicit InsertViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); 0035 ~InsertViMode() override; 0036 0037 bool handleKeypress(const QKeyEvent *e) override; 0038 0039 bool commandInsertFromAbove(); 0040 bool commandInsertFromBelow(); 0041 0042 bool commandDeleteWord(); 0043 bool commandDeleteLine(); 0044 bool commandNewLine(); 0045 bool commandDeleteCharBackward(); 0046 0047 bool commandIndent(); 0048 bool commandUnindent(); 0049 0050 bool commandToFirstCharacterInFile(); 0051 bool commandToLastCharacterInFile(); 0052 0053 bool commandMoveOneWordLeft(); 0054 bool commandMoveOneWordRight(); 0055 0056 bool commandCompleteNext(); 0057 bool commandCompletePrevious(); 0058 0059 bool commandInsertContentOfRegister(); 0060 bool commandSwitchToNormalModeForJustOneCommand(); 0061 0062 void setBlockPrependMode(Range blockRange); 0063 void setBlockAppendMode(Range blockRange, BlockInsert b); 0064 0065 void setCount(int count) 0066 { 0067 m_count = count; 0068 } 0069 void setCountedRepeatsBeginOnNewLine(bool countedRepeatsBeginOnNewLine) 0070 { 0071 m_countedRepeatsBeginOnNewLine = countedRepeatsBeginOnNewLine; 0072 } 0073 0074 protected: 0075 void leaveInsertMode(bool force = false); 0076 void completionFinished(); 0077 0078 protected: 0079 BlockInsert m_blockInsert; 0080 unsigned int m_eolPos; // length of first line in eol mode before text is appended 0081 Range m_blockRange; 0082 0083 QString m_keys; 0084 bool m_waitingRegister; 0085 0086 unsigned int m_count; 0087 bool m_countedRepeatsBeginOnNewLine; 0088 0089 bool m_isExecutingCompletion; 0090 QString m_textInsertedByCompletion; 0091 KTextEditor::Cursor m_textInsertedByCompletionEndPos; 0092 0093 private: 0094 KTEXTEDITOR_NO_EXPORT 0095 void textInserted(KTextEditor::Document *document, KTextEditor::Range range); 0096 }; 0097 } 0098 0099 #endif /* KATEVI_INSERT_VI_MODE_H */