File indexing completed on 2024-04-28 03:58:10
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 public: 0023 explicit VisualViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); 0024 0025 void init(); 0026 0027 bool isVisualLine() const 0028 { 0029 return m_mode == VisualLineMode; 0030 } 0031 0032 bool isVisualBlock() const 0033 { 0034 return m_mode == VisualBlockMode; 0035 } 0036 0037 void switchStartEnd(); 0038 void reset() override; 0039 void setVisualModeType(const ViMode mode); 0040 void saveRangeMarks(); 0041 0042 void setStart(const KTextEditor::Cursor c) 0043 { 0044 m_start = c; 0045 } 0046 0047 KTextEditor::Cursor getStart() 0048 { 0049 return m_start; 0050 } 0051 0052 void goToPos(const KTextEditor::Cursor c); 0053 0054 ViMode getLastVisualMode() const 0055 { 0056 return m_lastVisualMode; 0057 } 0058 0059 const KTextEditor::Cursor getStart() const 0060 { 0061 return m_start; 0062 } 0063 0064 // Selects all lines in range; 0065 void selectLines(KTextEditor::Range range); 0066 0067 // Selects range between c1 and c2, but includes the end cursor position. 0068 void selectInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); 0069 0070 // Select block between c1 and c2. 0071 void selectBlockInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); 0072 0073 protected: 0074 /** 0075 * Called when a motion/text object is used. Updates the cursor position 0076 * and modifies the range. A motion will only modify the end of the range 0077 * (i.e. move the cursor) while a text object may modify both the start and 0078 * the end. Overridden from the ModeBase class. 0079 */ 0080 void goToPos(const Range &r) override; 0081 0082 /** 0083 * Return commands available for this mode. 0084 * Overwritten in sub classes to replace them, must be a stable reference! 0085 */ 0086 virtual const std::vector<Command> &commands() override; 0087 0088 /** 0089 * Return motions available for this mode. 0090 * Overwritten in sub classes to replace them, must be a stable reference! 0091 */ 0092 virtual const std::vector<Motion> &motions() override; 0093 0094 public: 0095 /** 0096 * Updates the visual mode's range to reflect a new cursor position. This 0097 * needs to be called if modifying the range from outside the vi mode, e.g. 0098 * via mouse selection. 0099 */ 0100 void updateSelection(); 0101 0102 private: 0103 KTextEditor::Cursor m_start; 0104 ViMode m_mode, m_lastVisualMode; 0105 }; 0106 } 0107 0108 #endif /* KATEVI_VISUAL_VI_MODE_H */