File indexing completed on 2024-05-12 11:58:35
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Erlend Hamberg <ehamberg@gmail.com> 0003 SPDX-FileCopyrightText: 2009 Paul Gideon Dann <pdgiddie@gmail.com> 0004 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> 0005 SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KATEVI_VISUAL_VI_MODE_H 0011 #define KATEVI_VISUAL_VI_MODE_H 0012 0013 #include <ktexteditor/range.h> 0014 #include <vimode/modes/normalvimode.h> 0015 0016 namespace KateVi 0017 { 0018 class InputModeManager; 0019 0020 class VisualViMode : public NormalViMode 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 explicit VisualViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); 0026 0027 void init(); 0028 0029 bool isVisualLine() const 0030 { 0031 return m_mode == VisualLineMode; 0032 } 0033 0034 bool isVisualBlock() const 0035 { 0036 return m_mode == VisualBlockMode; 0037 } 0038 0039 void switchStartEnd(); 0040 void reset() override; 0041 void setVisualModeType(const ViMode mode); 0042 void saveRangeMarks(); 0043 0044 void setStart(const KTextEditor::Cursor c) 0045 { 0046 m_start = c; 0047 } 0048 0049 KTextEditor::Cursor getStart() 0050 { 0051 return m_start; 0052 } 0053 0054 void goToPos(const KTextEditor::Cursor c); 0055 0056 ViMode getLastVisualMode() const 0057 { 0058 return m_lastVisualMode; 0059 } 0060 0061 const KTextEditor::Cursor getStart() const 0062 { 0063 return m_start; 0064 } 0065 0066 // Selects all lines in range; 0067 void selectLines(KTextEditor::Range range); 0068 0069 // Selects range between c1 and c2, but includes the end cursor position. 0070 void selectInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); 0071 0072 // Select block between c1 and c2. 0073 void selectBlockInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); 0074 0075 protected: 0076 /** 0077 * Called when a motion/text object is used. Updates the cursor position 0078 * and modifies the range. A motion will only modify the end of the range 0079 * (i.e. move the cursor) while a text object may modify both the start and 0080 * the end. Overridden from the ModeBase class. 0081 */ 0082 void goToPos(const Range &r) override; 0083 0084 /** 0085 * Return commands available for this mode. 0086 * Overwritten in sub classes to replace them, must be a stable reference! 0087 */ 0088 virtual const std::vector<Command> &commands() override; 0089 0090 /** 0091 * Return motions available for this mode. 0092 * Overwritten in sub classes to replace them, must be a stable reference! 0093 */ 0094 virtual const std::vector<Motion> &motions() override; 0095 0096 public Q_SLOTS: 0097 /** 0098 * Updates the visual mode's range to reflect a new cursor position. This 0099 * needs to be called if modifying the range from outside the vi mode, e.g. 0100 * via mouse selection. 0101 */ 0102 void updateSelection(); 0103 0104 private: 0105 KTextEditor::Cursor m_start; 0106 ViMode m_mode, m_lastVisualMode; 0107 }; 0108 0109 } 0110 0111 #endif /* KATEVI_VISUAL_VI_MODE_H */