[rkward] rkward/windows: Some tweaks to invocation of completion list.

Thomas Friedrichsmeier null at kde.org
Fri Feb 1 10:55:30 GMT 2019


Git commit d08f3935f78b28d9dcbf3c6c67d2fc1da1216392 by Thomas Friedrichsmeier.
Committed on 01/02/2019 at 10:53.
Pushed by tfry into branch 'master'.

Some tweaks to invocation of completion list.

Automatic invocation just does not see to work correctly, for us.
At the same time, we *do* want to offer the kate keyword completion, so we need an ugly hack for that.

M  +15   -2    rkward/windows/rkcommandeditorwindow.cpp
M  +4    -0    rkward/windows/rkcommandeditorwindow.h

https://commits.kde.org/rkward/d08f3935f78b28d9dcbf3c6c67d2fc1da1216392

diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 218f85cc..34e0deca 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -222,6 +222,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 	connect (m_view, &KTextEditor::View::focusIn, this, &RKCommandEditorWindow::focusIn);
 
 	completion_model = 0;
+	kate_keyword_completion_model = 0;
 	cc_iface = 0;
 	hinter = 0;
 	if (use_r_highlighting) {
@@ -229,12 +230,18 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 		if (use_codehinting) {
 			cc_iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (m_view);
 			if (cc_iface) {
-				cc_iface->setAutomaticInvocationEnabled (true);
+				cc_iface->setAutomaticInvocationEnabled (false);
 				completion_model = new RKCodeCompletionModel (this);
 				completion_timer = new QTimer (this);
 				completion_timer->setSingleShot (true);
 				connect (completion_timer, &QTimer::timeout, this, &RKCommandEditorWindow::tryCompletion);
 				connect (m_doc, &KTextEditor::Document::textChanged, this, &RKCommandEditorWindow::tryCompletionProxy);
+
+				// HACK: I just can't see to make the object name completion model play nice with automatic invocation.
+				//       However, there is no official way to invoke all registered models, manually. So we try to hack our way
+				//       to a pointer to the default kate keyword completion model
+				kate_keyword_completion_model = editor->findChild<KTextEditor::CodeCompletionModel *> ();
+				if (!kate_keyword_completion_model) kate_keyword_completion_model = m_view->findChild<KTextEditor::CodeCompletionModel *> (QString());
 			} else {
 				RK_ASSERT (false);
 			}
@@ -766,6 +773,11 @@ KTextEditor::Range RKCodeCompletionModel::completionRange (KTextEditor::View *vi
 	return KTextEditor::Range (position.line (), start, position.line (), end);
 }
 
+KTextEditor::Range RKCodeCompletionModel::updateCompletionRange(KTextEditor::View *view, const KTextEditor::Range &range) {
+	updateCompletionList (view->document ()->text (range));
+	return range;
+}
+
 void RKCommandEditorWindow::tryCompletion () {
 	// TODO: merge this with RKConsole::doTabCompletion () somehow
 	RK_TRACE (COMMANDEDITOR);
@@ -790,10 +802,11 @@ void RKCommandEditorWindow::tryCompletion () {
 	if (word.length () >= RKSettingsModuleCommandEditor::completionMinChars ()) {
 		completion_model->updateCompletionList (word);
 		if (completion_model->isEmpty ()) {
-			cc_iface->abortCompletion ();
+			if (kate_keyword_completion_model && kate_keyword_completion_model->rowCount () < 1) cc_iface->abortCompletion ();
 		} else {
 			if (!cc_iface->isCompletionActive ()) {
 				cc_iface->startCompletion (range, completion_model);
+				if (kate_keyword_completion_model) cc_iface->startCompletion (range, kate_keyword_completion_model);
 			}
 		}
 	} else {
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 89ebe070..1520062a 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -113,6 +113,9 @@ public:
 
 	KTextEditor::Range completionRange (KTextEditor::View *view, const KTextEditor::Cursor &position) override;
 	QString filterString (KTextEditor::View *, const KTextEditor::Range &, const KTextEditor::Cursor &) override { return QString (); };
+	bool shouldAbortCompletion (KTextEditor::View *, const KTextEditor::Range &, const QString &) override { return false; }
+	KTextEditor::CodeCompletionModelControllerInterface::MatchReaction matchingItem (const QModelIndex &) override { return KTextEditor::CodeCompletionModelControllerInterface::None; };
+	KTextEditor::Range updateCompletionRange (KTextEditor::View *view, const KTextEditor::Range &range) override;
 
 	void updateCompletionList (const QString& symbol);
 	void completionInvoked (KTextEditor::View *, const KTextEditor::Range &, InvocationType) override;
@@ -242,6 +245,7 @@ private:
 	KTextEditor::MovingInterface *smart_iface;
 	RKFunctionArgHinter *hinter;
 	RKCodeCompletionModel *completion_model;
+	KTextEditor::CodeCompletionModel* kate_keyword_completion_model;
 
 	QTimer *completion_timer;
 



More information about the rkward-tracker mailing list