[rkward/work/new_completion_to_console] /: Start using new completion features in console.
Thomas Friedrichsmeier
null at kde.org
Sun Apr 26 19:55:39 BST 2020
Git commit 6a3258d943601896ea29dd04c99c9724d76ba118 by Thomas Friedrichsmeier.
Committed on 26/04/2020 at 18:54.
Pushed by tfry into branch 'work/new_completion_to_console'.
Start using new completion features in console.
Still fairly buggy, but at least callhint is looking good, already.
M +3 -0 ChangeLog
M +5 -28 rkward/rkconsole.cpp
M +1 -2 rkward/rkconsole.h
M +2 -1 rkward/settings/rksettings.cpp
M +8 -6 rkward/settings/rksettingsmodulecommandeditor.cpp
M +1 -1 rkward/settings/rksettingsmodulecommandeditor.h
M +14 -4 rkward/windows/rkcodecompletion.cpp
M +3 -0 rkward/windows/rkcodecompletion.h
https://commits.kde.org/rkward/6a3258d943601896ea29dd04c99c9724d76ba118
diff --git a/ChangeLog b/ChangeLog
index 68d96f0c..79ba9c74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@
- Support pdf?
- <text> elements in plugins may now also contain clickable links, including rkward://-scheme links
* TODO: Bring new code hinting features to the console window!
+ - Tab key (+option)
+ - Clean up unused code
+ - Enter key behavior
- 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 2a37f154..51ecfba1 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -2,7 +2,7 @@
rkconsole - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004-2019 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -54,6 +54,7 @@
#include "rkglobals.h"
#include "rkward.h"
#include "windows/rkhelpsearchwindow.h"
+#include "windows/rkcodecompletion.h"
#include "rbackend/rkrinterface.h"
#include "rbackend/rcommand.h"
#include "settings/rksettings.h"
@@ -110,9 +111,6 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
RK_ASSERT (view);
confint->setConfigValue ("dynamic-word-wrap", false);
- KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (view);
- if (iface) iface->setAutomaticInvocationEnabled (false);
-
setFocusProxy (view);
setFocusPolicy (Qt::StrongFocus);
@@ -140,11 +138,11 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
if (view->focusProxy ()) view->focusProxy()->installEventFilter(this);
view->installEventFilter(this);
+ auto manager = new RKCompletionManager (view, RKSettingsModuleConsole::completionSettings()); // Must be instantiated _after_ our event filter, so that it will apply its filter first
+ manager->setLinePrefixes(nprefix, iprefix);
doc->setModified (false);
- hinter = new RKFunctionArgHinter (this, view);
-
setCaption (i18n ("R Console"));
console_part = new RKConsolePart (this);
setPart (console_part);
@@ -175,7 +173,6 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
RKConsole::~RKConsole () {
RK_TRACE (APP);
- delete hinter;
RKSettingsModuleConsole::saveCommandHistory (commands_history.getHistory ());
}
@@ -271,21 +268,8 @@ bool RKConsole::handleKeyPress (QKeyEvent *e) {
Qt::KeyboardModifiers modifier = e->modifiers () & modifier_mask;
if ((key == Qt::Key_Up) || (key == Qt::Key_Down)) {
- KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (view);
- if (iface && iface->isCompletionActive ()) {
- if (key == Qt::Key_Up) triggerEditAction ("move_line_up");
- else triggerEditAction ("move_line_down");
- return true;
- }
-
- // showing completion list during history navigation is not a good idea, since it uses the same keys
- bool auto_inv = (iface && iface->isAutomaticInvocationEnabled ());
- if (iface) iface->setAutomaticInvocationEnabled (false);
-
if (key == Qt::Key_Up) commandsListUp (RKSettingsModuleConsole::shouldDoHistoryContextSensitive (modifier));
else commandsListDown (RKSettingsModuleConsole::shouldDoHistoryContextSensitive (modifier));
-
- if (iface) iface->setAutomaticInvocationEnabled (auto_inv);
return true;
}
@@ -326,14 +310,6 @@ bool RKConsole::handleKeyPress (QKeyEvent *e) {
cursorAtTheEnd ();
return true;
} else if (key == Qt::Key_Enter || key == Qt::Key_Return) {
- // currently, these are auto-text hints, only
- KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (view);
- if (iface && iface->isCompletionActive ()) {
- iface->forceCompletion ();
- return true;
- }
-
- hinter->hideArgHint ();
commands_history.append (currentEditingLine ());
submitCommand ();
return true;
@@ -377,6 +353,7 @@ bool RKConsole::handleKeyPress (QKeyEvent *e) {
}
return true;
} else if (key == Qt::Key_Tab) {
+#warning TODO
KTextEditor::CodeCompletionInterface *iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (view);
if (iface && iface->isCompletionActive ()) {
return false;
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index 5b7f20de..d68765c7 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -2,7 +2,7 @@
rkconsole - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004, 2006, 2007, 2010, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -130,7 +130,6 @@ friend class RKConsolePart;
RCommand *current_command;
KTextEditor::Document *doc;
KTextEditor::View *view;
- RKFunctionArgHinter *hinter;
static RKConsole *main_console;
diff --git a/rkward/settings/rksettings.cpp b/rkward/settings/rksettings.cpp
index 29720a9c..33a55f16 100644
--- a/rkward/settings/rksettings.cpp
+++ b/rkward/settings/rksettings.cpp
@@ -52,7 +52,7 @@ void RKSettings::configureSettings (SettingsPage page, QWidget *parent, RCommand
settings_dialog = new RKSettings (parent);
}
- settings_dialog->raisePage (page);
+ if (page != NoPage) settings_dialog->raisePage (page);
settings_dialog->show ();
settings_dialog->raise ();
}
@@ -74,6 +74,7 @@ void RKSettings::configureSettings (const QString& page, QWidget *parent, RComma
} else if (page == QStringLiteral ("rpackages")) {
RKSettings::configureSettings (RKSettings::PageRPackages, parent, chain);
} else {
+ RK_ASSERT(page.isEmpty());
RKSettings::configureSettings (RKSettings::NoPage, parent, chain);
}
}
diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index a04393c4..504fd926 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -80,11 +80,13 @@ RKCodeCompletionSettingsWidget::RKCodeCompletionSettingsWidget(QWidget *parent,
form_layout = new QFormLayout ();
box_layout->addLayout (form_layout);
- cursor_navigates_completions_box = new QCheckBox (i18n ("Up/down cursor keys navigate completion items"));
- cursor_navigates_completions_box->setChecked (settings->cursor_navigates_completions);
- RKCommonFunctions::setTips (i18n ("Should the up / down cursor keys be used to navigate among the completion items, while code completion is active? If this option is unchecked, Alt+up/down will navigate completion items, while up / down will behave as if no completion was active."), cursor_navigates_completions_box);
- connect (cursor_navigates_completions_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (cursor_navigates_completions_box);
+ cursor_navigates_completions_box = new QComboBox(group);
+ cursor_navigates_completions_box->addItem(i18n("Up/down cursor keys"));
+ cursor_navigates_completions_box->addItem(i18n("Alt+Up/down cursor keys"));
+ cursor_navigates_completions_box->setCurrentIndex(settings->cursor_navigates_completions ? 0 : 1);
+ RKCommonFunctions::setTips (i18n ("If you wish to avoid ambiguity between navigation completion options and navigating the document, you can set the behavior such that completion items are navigate using Alt+up / Alt+down, instead of just the up/down cursor keys."), cursor_navigates_completions_box);
+ connect (cursor_navigates_completions_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18n ("Keyboard navigation of completion items"), cursor_navigates_completions_box);
if (show_common) {
completion_list_member_operator_box = new QComboBox (group);
@@ -126,7 +128,7 @@ void RKCodeCompletionSettingsWidget::applyChanges() {
for (int i = 0; i < RKCodeCompletionSettings::N_COMPLETION_CATEGORIES; ++i) {
settings->completion_type_enabled[i] = completion_type_enabled_box[i]->isChecked ();
}
- settings->cursor_navigates_completions = cursor_navigates_completions_box->isChecked ();
+ settings->cursor_navigates_completions = (cursor_navigates_completions_box->currentIndex() == 0);
if (show_common) {
settings->completion_options = 0;
diff --git a/rkward/settings/rksettingsmodulecommandeditor.h b/rkward/settings/rksettingsmodulecommandeditor.h
index 3051ff38..341b1204 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.h
+++ b/rkward/settings/rksettingsmodulecommandeditor.h
@@ -77,7 +77,7 @@ private:
QGroupBox* auto_completion_enabled_box;
QCheckBox* auto_completion_cursor_activated_box;
QCheckBox* completion_type_enabled_box[RKCodeCompletionSettings::N_COMPLETION_CATEGORIES];
- QCheckBox* cursor_navigates_completions_box;
+ QComboBox* cursor_navigates_completions_box;
QComboBox* completion_list_member_operator_box;
QComboBox* completion_slot_operator_box;
QComboBox* completion_object_qualification_box;
diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 3617d934..71086cfb 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -218,15 +218,25 @@ void RKCompletionManager::updateCallHint () {
QString full_context;
int potential_symbol_end = -2;
int parenthesis_level = 0;
+ int prefix_offset = 0;
KTextEditor::Document *doc = _view->document ();
while (potential_symbol_end < -1 && line >= 0) {
--line;
QString context_line = doc->line (line);
- if (context_line.startsWith ('>')) continue; // For console: TODO limit to console
+ if (!prefix.isEmpty()) { // For skipping interactive output sections in console. Empty for RKCommandEditorWindow
+ if (context_line.startsWith(prefix)) {
+ prefix_offset = prefix.length();
+ } else if (context_line.startsWith(continuation_prefix)) {
+ prefix_offset = continuation_prefix.length();
+ } else {
+ continue;
+ }
+ context_line = context_line.mid(prefix_offset);
+ }
full_context.prepend (context_line);
int pos = context_line.length () - 1;
- if (line == cached_position.line ()) pos = cached_position.column () - 1;
+ if (line == cached_position.line ()) pos = cached_position.column () - 1 - prefix_offset; // when on current line, look backward from cursor position, not line end
for (int i = pos; i >= 0; --i) {
QChar c = context_line.at (i);
if (c == '(') {
@@ -399,11 +409,11 @@ bool RKCompletionManager::eventFilter (QObject*, QEvent* event) {
return true;
}
} else if ((k->key () == Qt::Key_Up || k->key () == Qt::Key_Down) && cc_iface->isCompletionActive ()) {
- if (settings->cursorNavigatesCompletions ()) return false;
+ bool navigate = (settings->cursorNavigatesCompletions() && k->modifiers() == Qt::NoModifier) || (!settings->cursorNavigatesCompletions() && k->modifiers() == Qt::AltModifier);
// Make up / down-keys (without alt) navigate in the document (aborting the completion)
// Make alt+up / alt+down navigate in the completion list
- if (k->modifiers () & Qt::AltModifier) {
+ if (navigate) {
if (k->type() != QKeyEvent::KeyPress) return true; // eat the release event
// No, we cannot just send a fake key event, easily...
diff --git a/rkward/windows/rkcodecompletion.h b/rkward/windows/rkcodecompletion.h
index 1d17398a..7044e9bc 100644
--- a/rkward/windows/rkcodecompletion.h
+++ b/rkward/windows/rkcodecompletion.h
@@ -46,6 +46,7 @@ public:
KTextEditor::Range currentArgnameRange () const { return argname_range; };
KTextEditor::Range currentCallRange () const;
KTextEditor::View* view () const { return (_view); };
+ void setLinePrefixes(const QString &_prefix, const QString &_continuation_prefix) { prefix = _prefix; continuation_prefix = _continuation_prefix; };
public slots:
void userTriggeredCompletion ();
private slots:
@@ -82,6 +83,8 @@ private:
bool keep_active;
bool user_triggered;
bool ignore_next_trigger;
+ QString prefix;
+ QString continuation_prefix;
QList<KTextEditor::CodeCompletionModel*> active_models;
};
More information about the rkward-tracker
mailing list