1/*
2 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com>
3 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATEVI_COMMAND_H
9#define KATEVI_COMMAND_H
10
11#include <QRegularExpression>
12#include <QString>
13
14namespace KateVi
15{
16class KeyParser;
17class NormalViMode;
18
19enum CommandFlags {
20 REGEX_PATTERN = 0x1, // the pattern is a regex
21 NEEDS_MOTION = 0x2, // the command needs a motion before it can be executed
22 SHOULD_NOT_RESET = 0x4, // the command should not cause the current mode to be left
23 IS_CHANGE = 0x8, // the command changes the buffer
24 IS_NOT_LINEWISE = 0x10, // the motion is not line wise
25 CAN_CHANGE_WHOLE_VISUAL_MODE_SELECTION = 0x20, // the motion is a text object that can set the
26 // whole Visual Mode selection to the text object
27 CAN_LAND_INSIDE_FOLDING_RANGE = 0x40 // the motion can end up inside a folding range
28};
29
30class Command
31{
32public:
33 Command(const QString &pattern, bool (NormalViMode::*pt2Func)(), unsigned int flags = 0);
34 virtual ~Command();
35
36 bool matches(const QString &pattern) const;
37 bool matchesExact(const QString &pattern) const;
38 bool execute(NormalViMode *mode) const;
39 const QString pattern() const
40 {
41 return m_pattern;
42 }
43 bool isRegexPattern() const
44 {
45 return m_flags & REGEX_PATTERN;
46 }
47 bool needsMotion() const
48 {
49 return m_flags & NEEDS_MOTION;
50 }
51 bool shouldReset() const
52 {
53 return !(m_flags & SHOULD_NOT_RESET);
54 }
55 bool isChange() const
56 {
57 return m_flags & IS_CHANGE;
58 }
59 bool isLineWise() const
60 {
61 return !(m_flags & IS_NOT_LINEWISE);
62 }
63 bool canChangeWholeVisualModeSelection() const
64 {
65 return m_flags & CAN_CHANGE_WHOLE_VISUAL_MODE_SELECTION;
66 }
67 bool canLandInsideFoldingRange() const
68 {
69 return m_flags & CAN_LAND_INSIDE_FOLDING_RANGE;
70 }
71
72protected:
73 // constant stuff, we create each command just once globally
74 const QString m_pattern;
75 const unsigned int m_flags;
76 bool (NormalViMode::*m_ptr2commandMethod)();
77
78 // we create commands only once globally
79 // regex compile is costly, we do this at first match of this command
80 mutable QRegularExpression m_patternRegex;
81 mutable QRegularExpression m_patternAnchoredRegex;
82};
83
84}
85
86#endif /* KATEVI_COMMAND_H */
87

source code of ktexteditor/src/vimode/command.h