10#include "katepartdebug.h"
11#include <KCompletionMatches>
13#include <ktexteditor/command.h>
16#define CMD_HIST_LENGTH 256
20 m_cmdCompletion.addItem(QStringLiteral(
"help"));
23KateCmd::~KateCmd() =
default;
27 const QStringList &l = cmd->
cmds();
29 for (
int z = 0; z < l.
count(); z++) {
30 if (m_dict.contains(l[z])) {
31 qCDebug(LOG_KTE) <<
"Command already registered: " << l[z] <<
". Aborting.";
36 for (
int z = 0; z < l.
count(); z++) {
37 m_dict.insert(l[z], cmd);
42 m_cmdCompletion.insertItems(l);
51 QHash<QString, KTextEditor::Command *>::const_iterator i = m_dict.
constBegin();
52 while (i != m_dict.constEnd()) {
53 if (i.value() == cmd) {
61 m_cmdCompletion.removeItem(*it1);
78 if (cmd.
length() >= 2 && cmd.
at(0) == QLatin1Char(
's') && (cmd.
at(1) == QLatin1Char(
'-') || cmd.
at(1) == QLatin1Char(
'_'))) {
79 return m_dict.value(QStringLiteral(
"s"));
82 for (; f < cmd.
length(); f++) {
83 if (cmd[f].isLetter()) {
86 if (b && (!cmd[f].isLetterOrNumber() && cmd[f] != QLatin1Char(
'-') && cmd[f] != QLatin1Char(
'_'))) {
90 return m_dict.value(cmd.
left(f));
95 return m_dict.values();
103KateCmd *KateCmd::self()
108void KateCmd::appendHistory(
const QString &cmd)
110 if (!m_history.isEmpty()) {
111 if (m_history.last() == cmd) {
116 if (m_history.count() == CMD_HIST_LENGTH) {
117 m_history.removeFirst();
120 m_history.append(cmd);
123const QString KateCmd::fromHistory(
int index)
const
125 if (index < 0 || index > m_history.count() - 1) {
128 return m_history[index];
133 return &m_cmdCompletion;
144KateCmdShellCompletion::KateCmdShellCompletion()
157 splitText(text, m_text_start, m_text_compl);
164void KateCmdShellCompletion::postProcessMatch(
QString *match)
const
166 if (
match->isNull()) {
170 match->prepend(m_text_start);
173void KateCmdShellCompletion::postProcessMatches(
QStringList *matches)
const
176 if (!(*it).isNull()) {
177 (*it).prepend(m_text_start);
185 if (!(*it).value().isNull()) {
186 (*it).value().prepend(m_text_start);
191void KateCmdShellCompletion::splitText(
const QString &text,
QString &text_start,
QString &text_compl)
const
193 bool in_quote =
false;
194 bool escaped =
false;
195 QChar p_last_quote_char;
196 int last_unquoted_space = -1;
198 for (
int pos = 0; pos < text.
length(); pos++) {
201 }
else if (in_quote && text[pos] == p_last_quote_char) {
203 }
else if (!in_quote && text[pos] == m_quote_char1) {
204 p_last_quote_char = m_quote_char1;
206 }
else if (!in_quote && text[pos] == m_quote_char2) {
207 p_last_quote_char = m_quote_char2;
209 }
else if (text[pos] == m_escape_char) {
211 }
else if (!in_quote && text[pos] == m_word_break_char) {
212 while (pos + 1 < text.
length() && text[pos + 1] == m_word_break_char) {
216 if (pos + 1 == text.
length()) {
220 last_unquoted_space = pos;
224 text_start = text.
left(last_unquoted_space + 1);
227 text_compl = text.
mid(last_unquoted_space + 1);
virtual QString makeCompletion(const QString &string)
void matches(const QStringList &matchlist)
void match(const QString &item)
An Editor command line command.
const QStringList & cmds() const
Return a list of strings a command may begin with.
KateCmd * cmdManager()
command manager
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
QString makeCompletion(const QString &text) override
Finds completions to the given text.
const_iterator constBegin() const const
qsizetype count() const const
const QChar at(qsizetype position) const const
QString left(qsizetype n) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const