Changeset View
Changeset View
Standalone View
Standalone View
src/vimode/cmds.cpp
Show All 31 Lines | |||||
32 | #include "kateviinputmode.h" | 32 | #include "kateviinputmode.h" | ||
33 | #include <vimode/inputmodemanager.h> | 33 | #include <vimode/inputmodemanager.h> | ||
34 | #include "globalstate.h" | 34 | #include "globalstate.h" | ||
35 | #include "marks.h" | 35 | #include "marks.h" | ||
36 | 36 | | |||
37 | #include <KLocalizedString> | 37 | #include <KLocalizedString> | ||
38 | 38 | | |||
39 | #include <QDir> | 39 | #include <QDir> | ||
40 | #include <QRegExp> | 40 | #include <QRegularExpression> | ||
41 | #include <QUrl> | 41 | #include <QUrl> | ||
42 | 42 | | |||
43 | using namespace KateVi; | 43 | using namespace KateVi; | ||
44 | 44 | | |||
45 | //BEGIN ViCommands | 45 | //BEGIN ViCommands | ||
46 | Commands *Commands::m_instance = nullptr; | 46 | Commands *Commands::m_instance = nullptr; | ||
47 | 47 | | |||
48 | bool Commands::exec(KTextEditor::View *view, const QString &_cmd, | 48 | bool Commands::exec(KTextEditor::View *view, const QString &_cmd, | ||
49 | QString &msg, const KTextEditor::Range &range) | 49 | QString &msg, const KTextEditor::Range &range) | ||
50 | { | 50 | { | ||
51 | Q_UNUSED(range) | 51 | Q_UNUSED(range) | ||
52 | // cast it hardcore, we know that it is really a kateview :) | 52 | // cast it hardcore, we know that it is really a kateview :) | ||
53 | KTextEditor::ViewPrivate *v = static_cast<KTextEditor::ViewPrivate *>(view); | 53 | KTextEditor::ViewPrivate *v = static_cast<KTextEditor::ViewPrivate *>(view); | ||
54 | 54 | | |||
55 | if (!v) { | 55 | if (!v) { | ||
56 | msg = i18n("Could not access view"); | 56 | msg = i18n("Could not access view"); | ||
57 | return false; | 57 | return false; | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | //create a list of args | 60 | //create a list of args | ||
61 | QStringList args(_cmd.split(QRegExp(QLatin1String("\\s+")), QString::SkipEmptyParts)); | 61 | QStringList args(_cmd.split(QRegularExpression(QLatin1String("\\s+")), QString::SkipEmptyParts)); | ||
62 | QString cmd(args.takeFirst()); | 62 | QString cmd(args.takeFirst()); | ||
63 | 63 | | |||
64 | // ALL commands that takes no arguments. | 64 | // ALL commands that takes no arguments. | ||
65 | if (mappingCommands().contains(cmd)) { | 65 | if (mappingCommands().contains(cmd)) { | ||
66 | if (cmd.endsWith(QLatin1String("unmap"))) { | 66 | if (cmd.endsWith(QLatin1String("unmap"))) { | ||
67 | if (args.count() == 1) { | 67 | if (args.count() == 1) { | ||
68 | m_viGlobal->mappings()->remove(modeForMapCommand(cmd), args.at(0)); | 68 | m_viGlobal->mappings()->remove(modeForMapCommand(cmd), args.at(0)); | ||
69 | return true; | 69 | return true; | ||
Show All 31 Lines | 96 | if (cmd == QLatin1String("d") || cmd == QLatin1String("delete") || cmd == QLatin1String("j") || | |||
101 | 101 | | |||
102 | int count = 1; | 102 | int count = 1; | ||
103 | if (range.isValid()) { | 103 | if (range.isValid()) { | ||
104 | count = qAbs(range.end().line() - range.start().line()) + 1; | 104 | count = qAbs(range.end().line() - range.start().line()) + 1; | ||
105 | v->setCursorPosition(KTextEditor::Cursor(qMin(range.start().line(), | 105 | v->setCursorPosition(KTextEditor::Cursor(qMin(range.start().line(), | ||
106 | range.end().line()), 0)); | 106 | range.end().line()), 0)); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | QRegExp number(QLatin1String("^(\\d+)$")); | 109 | static const QRegularExpression number(QLatin1String("^(\\d+)$")); | ||
110 | for (int i = 0; i < args.count(); i++) { | 110 | for (int i = 0; i < args.count(); i++) { | ||
111 | if (number.indexIn(args.at(i)) != -1) { | 111 | auto match = number.match(args.at(i)); | ||
112 | count += number.cap().toInt() - 1; | 112 | if (match.hasMatch()) { | ||
113 | count += match.captured(0).toInt() - 1; | ||||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | QChar r = args.at(i).at(0); | 116 | QChar r = args.at(i).at(0); | ||
116 | if (args.at(i).size() == 1 && ((r >= QLatin1Char('a') && r <= QLatin1Char('z')) || r == QLatin1Char('_') || r == QLatin1Char('+') || r == QLatin1Char('*'))) { | 117 | if (args.at(i).size() == 1 && ((r >= QLatin1Char('a') && r <= QLatin1Char('z')) || r == QLatin1Char('_') || r == QLatin1Char('+') || r == QLatin1Char('*'))) { | ||
117 | nm->setRegister(r); | 118 | nm->setRegister(r); | ||
118 | } | 119 | } | ||
119 | } | 120 | } | ||
120 | 121 | | |||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |