File indexing completed on 2024-05-12 15:46:28
0001 /* 0002 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KATEVI_REPLACE_VI_MODE_H 0008 #define KATEVI_REPLACE_VI_MODE_H 0009 0010 #include <vimode/modes/modebase.h> 0011 0012 namespace KateVi 0013 { 0014 /** 0015 * Commands for the vi replace mode 0016 */ 0017 class ReplaceViMode : public ModeBase 0018 { 0019 public: 0020 explicit ReplaceViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); 0021 0022 /// Update the track of overwritten characters with the \p s character. 0023 inline void overwrittenChar(const QChar &s) 0024 { 0025 m_overwritten += s; 0026 } 0027 0028 void setCount(int count) 0029 { 0030 m_count = count; 0031 } 0032 0033 protected: 0034 /** 0035 * Checks if the key is a valid command in replace mode. 0036 * 0037 * @returns true if a command was completed and executed, false otherwise. 0038 */ 0039 bool handleKeypress(const QKeyEvent *e) override; 0040 0041 private: 0042 /** 0043 * Replace the character at the current column with a character from 0044 * the same column but in a different line. 0045 * 0046 * @param offset The offset of the line to be picked. This value is 0047 * relative to the current line. 0048 * @returns true if the character could be replaced, false otherwise. 0049 */ 0050 bool commandInsertFromLine(int offset); 0051 0052 // Auxiliar methods for moving the cursor in replace mode. 0053 0054 bool commandMoveOneWordLeft(); 0055 bool commandMoveOneWordRight(); 0056 0057 // Auxiliar methods for removing modifications. 0058 0059 void backspace(); 0060 void commandBackWord(); 0061 void commandBackLine(); 0062 void leaveReplaceMode(); 0063 0064 protected: 0065 unsigned int m_count; 0066 0067 private: 0068 /// Keeps track of the characters that have been overwritten so far. 0069 QString m_overwritten; 0070 }; 0071 0072 } 0073 0074 #endif /* KATEVI_REPLACE_VI_MODE_H */