File indexing completed on 2024-03-24 04:00:55
0001 /* 0002 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com> 0003 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KATEVI_COMMAND_H 0009 #define KATEVI_COMMAND_H 0010 0011 #include <QRegularExpression> 0012 #include <QString> 0013 0014 namespace KateVi 0015 { 0016 class KeyParser; 0017 class NormalViMode; 0018 0019 enum CommandFlags { 0020 REGEX_PATTERN = 0x1, // the pattern is a regex 0021 NEEDS_MOTION = 0x2, // the command needs a motion before it can be executed 0022 SHOULD_NOT_RESET = 0x4, // the command should not cause the current mode to be left 0023 IS_CHANGE = 0x8, // the command changes the buffer 0024 IS_NOT_LINEWISE = 0x10, // the motion is not line wise 0025 CAN_CHANGE_WHOLE_VISUAL_MODE_SELECTION = 0x20, // the motion is a text object that can set the 0026 // whole Visual Mode selection to the text object 0027 CAN_LAND_INSIDE_FOLDING_RANGE = 0x40 // the motion can end up inside a folding range 0028 }; 0029 0030 class Command 0031 { 0032 public: 0033 Command(const QString &pattern, bool (NormalViMode::*pt2Func)(), unsigned int flags = 0); 0034 virtual ~Command(); 0035 0036 bool matches(const QString &pattern) const; 0037 bool matchesExact(const QString &pattern) const; 0038 bool execute(NormalViMode *mode) const; 0039 const QString pattern() const 0040 { 0041 return m_pattern; 0042 } 0043 bool isRegexPattern() const 0044 { 0045 return m_flags & REGEX_PATTERN; 0046 } 0047 bool needsMotion() const 0048 { 0049 return m_flags & NEEDS_MOTION; 0050 } 0051 bool shouldReset() const 0052 { 0053 return !(m_flags & SHOULD_NOT_RESET); 0054 } 0055 bool isChange() const 0056 { 0057 return m_flags & IS_CHANGE; 0058 } 0059 bool isLineWise() const 0060 { 0061 return !(m_flags & IS_NOT_LINEWISE); 0062 } 0063 bool canChangeWholeVisualModeSelection() const 0064 { 0065 return m_flags & CAN_CHANGE_WHOLE_VISUAL_MODE_SELECTION; 0066 } 0067 bool canLandInsideFoldingRange() const 0068 { 0069 return m_flags & CAN_LAND_INSIDE_FOLDING_RANGE; 0070 } 0071 0072 protected: 0073 // constant stuff, we create each command just once globally 0074 const QString m_pattern; 0075 const unsigned int m_flags; 0076 bool (NormalViMode::*m_ptr2commandMethod)(); 0077 0078 // we create commands only once globally 0079 // regex compile is costly, we do this at first match of this command 0080 mutable QRegularExpression m_patternRegex; 0081 mutable QRegularExpression m_patternAnchoredRegex; 0082 }; 0083 0084 } 0085 0086 #endif /* KATEVI_COMMAND_H */