1 | /* |
2 | SPDX-FileCopyrightText: 2008-2009 Erlend Hamberg <ehamberg@gmail.com> |
3 | SPDX-FileCopyrightText: 2009 Paul Gideon Dann <pdgiddie@gmail.com> |
4 | SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> |
5 | SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com> |
6 | |
7 | SPDX-License-Identifier: LGPL-2.0-or-later |
8 | */ |
9 | |
10 | #ifndef KATEVI_VISUAL_VI_MODE_H |
11 | #define KATEVI_VISUAL_VI_MODE_H |
12 | |
13 | #include <ktexteditor/range.h> |
14 | #include <vimode/modes/normalvimode.h> |
15 | |
16 | namespace KateVi |
17 | { |
18 | class InputModeManager; |
19 | |
20 | class VisualViMode : public NormalViMode |
21 | { |
22 | public: |
23 | explicit VisualViMode(InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view, KateViewInternal *viewInternal); |
24 | |
25 | void init(); |
26 | |
27 | bool isVisualLine() const |
28 | { |
29 | return m_mode == VisualLineMode; |
30 | } |
31 | |
32 | bool isVisualBlock() const |
33 | { |
34 | return m_mode == VisualBlockMode; |
35 | } |
36 | |
37 | void switchStartEnd(); |
38 | void reset() override; |
39 | void setVisualModeType(const ViMode mode); |
40 | void saveRangeMarks(); |
41 | |
42 | void setStart(const KTextEditor::Cursor c) |
43 | { |
44 | m_start = c; |
45 | } |
46 | |
47 | KTextEditor::Cursor getStart() |
48 | { |
49 | return m_start; |
50 | } |
51 | |
52 | void goToPos(const KTextEditor::Cursor c); |
53 | |
54 | ViMode getLastVisualMode() const |
55 | { |
56 | return m_lastVisualMode; |
57 | } |
58 | |
59 | const KTextEditor::Cursor getStart() const |
60 | { |
61 | return m_start; |
62 | } |
63 | |
64 | // Selects all lines in range; |
65 | void selectLines(KTextEditor::Range range); |
66 | |
67 | // Selects range between c1 and c2, but includes the end cursor position. |
68 | void selectInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); |
69 | |
70 | // Select block between c1 and c2. |
71 | void selectBlockInclusive(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2); |
72 | |
73 | protected: |
74 | /** |
75 | * Called when a motion/text object is used. Updates the cursor position |
76 | * and modifies the range. A motion will only modify the end of the range |
77 | * (i.e. move the cursor) while a text object may modify both the start and |
78 | * the end. Overridden from the ModeBase class. |
79 | */ |
80 | void goToPos(const Range &r) override; |
81 | |
82 | /** |
83 | * Return commands available for this mode. |
84 | * Overwritten in sub classes to replace them, must be a stable reference! |
85 | */ |
86 | virtual const std::vector<Command> &commands() override; |
87 | |
88 | /** |
89 | * Return motions available for this mode. |
90 | * Overwritten in sub classes to replace them, must be a stable reference! |
91 | */ |
92 | virtual const std::vector<Motion> &motions() override; |
93 | |
94 | public: |
95 | /** |
96 | * Updates the visual mode's range to reflect a new cursor position. This |
97 | * needs to be called if modifying the range from outside the vi mode, e.g. |
98 | * via mouse selection. |
99 | */ |
100 | void updateSelection(); |
101 | |
102 | private: |
103 | KTextEditor::Cursor m_start; |
104 | ViMode m_mode, m_lastVisualMode; |
105 | }; |
106 | } |
107 | |
108 | #endif /* KATEVI_VISUAL_VI_MODE_H */ |
109 | |