[rkward/work/new_completion_to_console] /: Remove now obsolete console tab key handling
Thomas Friedrichsmeier
null at kde.org
Sat May 2 11:10:46 BST 2020
Git commit dd88eba07b5a29d3c54ebc2be01930ba47871921 by Thomas Friedrichsmeier.
Committed on 02/05/2020 at 10:10.
Pushed by tfry into branch 'work/new_completion_to_console'.
Remove now obsolete console tab key handling
M +0 -1 ChangeLog
M +0 -107 rkward/rkconsole.cpp
M +0 -4 rkward/rkconsole.h
https://commits.kde.org/rkward/dd88eba07b5a29d3c54ebc2be01930ba47871921
diff --git a/ChangeLog b/ChangeLog
index c307d929..9464ee89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,7 +6,6 @@
- Support pdf?
- <text> elements in plugins may now also contain clickable links, including rkward://-scheme links
- The new code hinting features from version 0.7.1 are now also available in the console
- * TODO: Clean up unused code
- On unix-systems, RKWard can now be run without installation
- TODO: common.js is not found in plugins!
- Kate addons are now supported within RKWard. Intially, search-in-files, snippets, and projects are loaded by default
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 51ecfba1..54c152db 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -352,14 +352,6 @@ bool RKConsole::handleKeyPress (QKeyEvent *e) {
doc->removeText (KTextEditor::Range (para, pos, para, pos + 1));
}
return true;
- } else if (key == Qt::Key_Tab) {
-#warning TODO
- KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (view);
- if (iface && iface->isCompletionActive ()) {
- return false;
- }
- doTabCompletion ();
- return true;
}
return false;
@@ -379,105 +371,6 @@ QString RKConsole::provideContext (int line_rev) {
return ret;
}
-void RKConsole::insertCompletion (int line_num, int word_start, int word_end, const QString &completion) {
- RK_TRACE (APP);
-
- int offset = prefix.length ();
- doc->replaceText (KTextEditor::Range (line_num, offset + word_start, line_num, offset + word_end), completion);
-}
-
-bool RKConsole::doTabCompletionHelper (int line_num, const QString &line, int word_start, int word_end, const QStringList &entries) {
- RK_TRACE (APP);
-
- int count = entries.count ();
- QStringList::const_iterator it;
- if (!count) return false;
-
- if (count == 1) {
- it = entries.constBegin ();
- insertCompletion (line_num, word_start, word_end, *it);
- } else if (tab_key_pressed_before) {
- int i=0;
- for (it = entries.constBegin (); it != entries.constEnd (); ++it) {
- if (i % 3) {
- doc->insertText (KTextEditor::Cursor (doc->lines () - 1, 0), (*it).leftJustified (35));
- } else {
- doc->insertLine (doc->lines (), *it);
- }
- ++i;
- }
- doc->insertLine (doc->lines (), prefix + line);
- cursorAtTheEnd ();
- } else {
- tab_key_pressed_before = true;
-
- // do all entries have a common start?
- QString common;
- bool done = false;
- int i = 0;
- while (!done) {
- bool ok = true;
- QChar current;
- for (it = entries.constBegin (); it != entries.constEnd (); ++it) {
- if ((*it).length () <= i) {
- ok = false;
- break;
- }
- if (it == entries.constBegin ()) {
- current = (*it).at(i);
- } else if ((*it).at(i) != current) {
- ok = false;
- break;
- }
- }
- if (ok) common.append (current);
- else break;
- ++i;
- }
- if (i > 0) {
- if ((int) common.length() > (word_end - word_start)) { // more than there already is
- insertCompletion (line_num, word_start, word_end, common);
- return false; // will beep to signal completion is not complete
- }
- }
-
- return true;
- }
- tab_key_pressed_before = false;
- return true;
-}
-
-
-void RKConsole::doTabCompletion () {
- RK_TRACE (APP);
-
- QString current_line = currentEditingLine ();
- int current_line_num = doc->lines () - 1;
- int word_start;
- int word_end;
- int cursor_pos = currentCursorPositionInCommand ();
- if (cursor_pos < 0) cursor_pos = current_line.length ();
- RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &word_start, &word_end);
- QString current_symbol = current_line.mid (word_start, word_end - word_start);
-
- // 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 (current_symbol.startsWith ('\"') || current_symbol.startsWith ('\'') || current_symbol.startsWith ('`')) {
- KUrlCompletion comp (KUrlCompletion::FileCompletion);
- comp.setDir (QUrl::fromLocalFile (QDir::currentPath ()));
- comp.makeCompletion (current_symbol.mid (1));
-
- if (doTabCompletionHelper (current_line_num, current_line, word_start + 1, word_end, comp.allMatches ())) return;
- } else if (!current_symbol.isEmpty ()) {
- RObject::ObjectList matches;
- matches = RObjectList::getObjectList ()->findObjectsMatching (current_symbol);
- QStringList match_names = RObject::getFullNames (matches, RObject::IncludeEnvirIfMasked);
- if (doTabCompletionHelper (current_line_num, current_line, word_start, word_end, match_names)) return;
- }
-
- // no completion was possible
- qApp->beep ();
-}
-
bool RKConsole::eventFilter (QObject *o, QEvent *e) {
if (o == getPart ()) {
return RKMDIWindow::eventFilter (o, e);
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index d68765c7..c757c7c1 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -60,7 +60,6 @@ public:
QString currentEditingLine () const;
/** Returns the current cursor position, within the current command (without taking into account the prefix). Returns -1 if the cursor is not on the line containing the command. */
int currentCursorPositionInCommand ();
- void doTabCompletion ();
QString provideContext (int line_rev) override;
void currentHelpContext (QString *symbol, QString *package) override;
@@ -88,9 +87,6 @@ protected:
private:
friend class RKConsolePart;
bool eventFilter (QObject *o, QEvent *e) override;
- bool doTabCompletionHelper (int line_num, const QString &line, int word_start, int word_end, const QStringList &entries);
-/** a helper function to doTabCompletionHelper */
- void insertCompletion (int line_num, int word_start, int word_end, const QString &completion);
QString incomplete_command;
/** A list to store previous commands */
RKCommandHistory commands_history;
More information about the rkward-tracker
mailing list