[rkward] rkward: Allow to trigger completion using (ktexteditor-provided) shortcut, even if automatic completion conditions are not met.
Thomas Friedrichsmeier
null at kde.org
Thu Feb 21 10:22:49 GMT 2019
Git commit 603fbc0cb1d88c5d64988df7ce85b2cc6489ce5b by Thomas Friedrichsmeier.
Committed on 21/02/2019 at 10:21.
Pushed by tfry into branch 'master'.
Allow to trigger completion using (ktexteditor-provided) shortcut, even if automatic completion conditions are not met.
M +1 -0 rkward/rkconsole.cpp
M +30 -9 rkward/windows/rkcodecompletion.cpp
M +4 -0 rkward/windows/rkcodecompletion.h
M +0 -3 rkward/windows/rkcommandeditorwindow.h
https://commits.kde.org/rkward/603fbc0cb1d88c5d64988df7ce85b2cc6489ce5b
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 943aeea2..2a37f154 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -43,6 +43,7 @@
#include <kshellcompletion.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/configinterface.h>
+#include <ktexteditor/codecompletioninterface.h>
#include <ktexteditor/markinterface.h>
#include <ktexteditor_version.h>
#include <kxmlguifactory.h>
diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 33c7fcee..b504af15 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -42,6 +42,7 @@ RKCompletionManager::RKCompletionManager (KTextEditor::View* view) : QObject (vi
_view = view;
active = false;
+ user_triggered = false;
update_call = true;
cached_position = KTextEditor::Cursor (-1, -1);
@@ -52,7 +53,7 @@ RKCompletionManager::RKCompletionManager (KTextEditor::View* view) : QObject (vi
file_completion_model = new RKFileCompletionModel (this);
callhint_model = new RKCallHintModel (this);
arghint_model = new RKArgumentHintModel (this);
- cc_iface->registerCompletionModel (callhint_model);
+ cc_iface->registerCompletionModel (completion_model); // (at least) one model needs to be registerd, so we will know, when completion was triggered by the user (shortcut)
completion_timer = new QTimer (this);
completion_timer->setSingleShot (true);
connect (completion_timer, &QTimer::timeout, this, &RKCompletionManager::tryCompletion);
@@ -100,6 +101,16 @@ QString RKCompletionManager::currentCompletionWord () const {
return QString ();
}
+void RKCompletionManager::userTriggeredCompletion () {
+ RK_TRACE (COMMANDEDITOR);
+
+ user_triggered = true;
+ completion_timer->stop ();
+ tryCompletion ();
+ user_triggered = false;
+ // NOTE: Sometimes (non-determinate) the completion window will disappear directly after this. It does not seem to be our fault, here, according to the tests I did.
+}
+
void RKCompletionManager::tryCompletion () {
// TODO: merge this with RKConsole::doTabCompletion () somehow
RK_TRACE (COMMANDEDITOR);
@@ -118,13 +129,15 @@ void RKCompletionManager::tryCompletion () {
int start;
int end;
RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos-1, false, &start, &end);
- if (end > cursor_pos) {
- symbol_range = KTextEditor::Range (-1, -1, -1, -1); // Only hint when at the end of a word/symbol: https://mail.kde.org/pipermail/rkward-devel/2015-April/004122.html
- } else if (current_line.lastIndexOf ("#", cursor_pos) >= 0) symbol_range = KTextEditor::Range (); // do not hint while in comments
- else symbol_range = KTextEditor::Range (para, start, para, end);
+ symbol_range = KTextEditor::Range (para, start, para, end);
+ if (!user_triggered) {
+ if (end > cursor_pos) {
+ symbol_range = KTextEditor::Range (-1, -1, -1, -1); // Only hint when at the end of a word/symbol: https://mail.kde.org/pipermail/rkward-devel/2015-April/004122.html
+ } else if (current_line.lastIndexOf ("#", cursor_pos) >= 0) symbol_range = KTextEditor::Range (); // do not hint while in comments
+ }
QString word = currentCompletionWord ();
- if (word.length () >= RKSettingsModuleCommandEditor::completionMinChars ()) {
+ if (user_triggered || (word.length () >= RKSettingsModuleCommandEditor::completionMinChars ())) {
QString filename;
// as a very simple heuristic: If the current symbol starts with a quote, we should probably attempt file name completion, instead of symbol name completion
if (word.startsWith ('\"') || word.startsWith ('\'') || word.startsWith ('`')) {
@@ -226,11 +239,11 @@ void startModel (KTextEditor::CodeCompletionInterface* iface, KTextEditor::CodeC
void RKCompletionManager::updateVisibility () {
RK_TRACE (COMMANDEDITOR);
- if (!cc_iface->isCompletionActive ()) {
+ if (user_triggered || !cc_iface->isCompletionActive ()) {
active_models.clear ();
}
- bool min_len = (currentCompletionWord ().length () >= RKSettingsModuleCommandEditor::completionMinChars ());
+ bool min_len = (currentCompletionWord ().length () >= RKSettingsModuleCommandEditor::completionMinChars ()) || user_triggered;
startModel (cc_iface, completion_model, min_len, symbol_range, &active_models);
startModel (cc_iface, file_completion_model, min_len, symbol_range, &active_models);
if (kate_keyword_completion_model) {
@@ -513,6 +526,15 @@ QString RKCodeCompletionModel::partialCompletion (bool* exact_match) {
return (findCommonCompletion (shortnames, lead, exact_match));
}
+void RKCodeCompletionModel::completionInvoked (KTextEditor::View* view, const KTextEditor::Range& range, KTextEditor::CodeCompletionModel::InvocationType invocationType) {
+ RK_TRACE (COMMANDEDITOR);
+
+ if (invocationType == KTextEditor::CodeCompletionModel::UserInvocation) {
+ manager->userTriggeredCompletion ();
+ }
+}
+
+
//////////////////////// RKCallHintModel //////////////////////////
RKCallHintModel::RKCallHintModel (RKCompletionManager* manager) : RKCompletionModelBase (manager) {
RK_TRACE (COMMANDEDITOR);
@@ -634,7 +656,6 @@ void RKArgumentHintModel::updateCompletionList (RObject* _function, const QStrin
if (changed) {
n_completions = matches.size ();
-RK_DEBUG(COMMANDEDITOR, DL_ERROR, "%d matches", n_completions);
endResetModel ();
}
}
diff --git a/rkward/windows/rkcodecompletion.h b/rkward/windows/rkcodecompletion.h
index fd778ad1..c3a1c878 100644
--- a/rkward/windows/rkcodecompletion.h
+++ b/rkward/windows/rkcodecompletion.h
@@ -43,6 +43,7 @@ public:
KTextEditor::Range currentArgnameRange () const { return argname_range; };
KTextEditor::Range currentCallRange () const;
KTextEditor::View* view () const { return (_view); };
+ void userTriggeredCompletion ();
private slots:
void lineWrapped (KTextEditor::Document *document, const KTextEditor::Cursor &position);
void lineUnwrapped (KTextEditor::Document *document, int line);
@@ -74,6 +75,7 @@ private:
bool update_call;
bool active;
+ bool user_triggered;
QList<KTextEditor::CodeCompletionModel*> active_models;
};
@@ -112,6 +114,8 @@ public:
~RKCodeCompletionModel ();
KTextEditor::Range completionRange (KTextEditor::View *view, const KTextEditor::Cursor &position) override;
+ /** reimplemented in one of the models, in order to receive notification, when completion is invoked manually. */
+ void completionInvoked (KTextEditor::View* view, const KTextEditor::Range& range, KTextEditor::CodeCompletionModel::InvocationType invocationType) override;
void updateCompletionList (const QString& symbol);
QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const override;
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 3273263b..1691d7df 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -24,9 +24,6 @@
#include <ktexteditor/view.h>
#include <ktexteditor/document.h>
-#include <ktexteditor/codecompletionmodel.h>
-#include <ktexteditor/codecompletioninterface.h>
-#include <ktexteditor/codecompletionmodelcontrollerinterface.h>
#include <ktexteditor/movingrange.h>
#include <ktexteditor/movinginterface.h>
More information about the rkward-tracker
mailing list