[education/rkward] /: Add combi-action to run current statement and advance
Thomas Friedrichsmeier
null at kde.org
Mon May 26 15:06:38 BST 2025
Git commit d1043ed0351a575334239bd750662c983438d077 by Thomas Friedrichsmeier.
Committed on 26/05/2025 at 14:06.
Pushed by tfry into branch 'master'.
Add combi-action to run current statement and advance
M +1 -0 ChangeLog
M +7 -5 rkward/pages/rkward_code_navigation.rkh
M +11 -2 rkward/windows/rkcodenavigation.cpp
https://invent.kde.org/education/rkward/-/commit/d1043ed0351a575334239bd750662c983438d077
diff --git a/ChangeLog b/ChangeLog
index b62a1734d..0958fb1d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
--- Version 0.8.2 - UNRELEASED
+- Added: Actions to navigate R code based on its structure & Quick Code Navigation Mode
- Added: Plugins: Enhance addChangeCommand() to allow writing more readable GUI logic code
- Added: Plugins: Simplify running R commands inside GUI logic code
- Fixed: Crash on script errors in plugins
diff --git a/rkward/pages/rkward_code_navigation.rkh b/rkward/pages/rkward_code_navigation.rkh
index 2d7323631..b200484d4 100644
--- a/rkward/pages/rkward_code_navigation.rkh
+++ b/rkward/pages/rkward_code_navigation.rkh
@@ -24,12 +24,13 @@ The code navigation feature is available from the <i>Run</i>-menu, and the conte
<tr><td><tt><b>1 / !</b></tt></td><td>Go to the top / bottom of the document</td></tr>
<tr><td><tt><b>s</b></tt></td><td>Select the current statement</td></tr>
<tr><td><tt><b>S</b></tt></td><td>(For R Markdown documents, only:) Select add code in the current chunk</td></tr>
+<tr><td><tt><b>r</b></tt></td><td>Run the current statement and advance to the next statement (equivalent to the sequence <tt>s - Ctrl+Return - n</tt>)</td></tr>
<tr><td><tt><b>Backspace</b></tt></td><td>Go back to the position before the latest action</td></tr>
-<tr><td><tt><b>Esc</b></tt></td><td>Exit code navigation mode, and reset the cursor / selection to the state before entering it</td></tr>
-<tr><td><tt><b>Return</b></tt></td><td>Exit code navigation mode, keeping current position/selection</td></tr>
-<tr><td></td><td>Code navigation will also end, if you click anywhere else in the script, switch to a different window, or the script is modified</td></tr>
+<tr><td><tt><b>Esc</b></tt></td><td>Exit Quick Code Navigation mode, and reset the cursor / selection to the state before entering it</td></tr>
+<tr><td><tt><b>Return</b></tt></td><td>Exit Quick Code Navigation mode, keeping current position/selection</td></tr>
+<tr><td></td><td>Quick Code Navigation mode will also end, if you click anywhere else in the script, switch to a different window, or the script is modified</td></tr>
<tr><td colspan="2"> </td></tr>
-<tr><td colspan="2">Finally, you can continue to use regular shortcuts, while in code navigation mode. This includes, importantly:</td></tr>
+<tr><td colspan="2">Finally, you can continue to use regular shortcuts, while in Quick Code Navigation mode. This includes, importantly:</td></tr>
<tr><td><tt><b>Ctrl+Return</b></tt></td><td>Run the current line or selection</td></tr>
</table>
</section>
@@ -37,7 +38,8 @@ The code navigation feature is available from the <i>Run</i>-menu, and the conte
<section title="Notes and Tips" id="tips">
The 'n' action is meant to remind of the corresponding step command in the R debugger (see <link href="rkward://rhelp/browser"/>), but it is
not the same. The most important difference being that the code navigation, described here, works on a fully static parsed representation of the script,
-and does not attempt to follow control flow, at all.
+and does not attempt to follow control flow, at all. Further, a well formed syntax is assumed, syntax errors will be skipped over, which may lead to
+unexpected behavior.
Further, what exactly is a "statement", and "inner", or and "outer" context may not always be quite clear, and may not always correspond exactly to the way
the R engine sees your code. Instead, these commands are meant to behave in a way, that we hope makes sense, intuitively. Remember to always control, visually, what you are doing, before you hit Ctrl+Enter.
diff --git a/rkward/windows/rkcodenavigation.cpp b/rkward/windows/rkcodenavigation.cpp
index 7033ac67f..d026dc796 100644
--- a/rkward/windows/rkcodenavigation.cpp
+++ b/rkward/windows/rkcodenavigation.cpp
@@ -24,6 +24,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include "../misc/rkparsedscript.h"
#include "../misc/rkstyle.h"
+#include "../rkconsole.h"
#include "rkworkplace.h"
#include "../debug.h"
@@ -99,6 +100,11 @@ class RKCodeNavigationInternal : public QObject {
auto posa = ps.getContext(ps.firstContextInChunk(ci)).start;
auto posb = ps.lastPositionInChunk(ci);
newpos.selection = KTextEditor::Range(positionToCursor(posa), positionToCursor(posb + 1));
+ } else if (command == u'r') {
+ auto posa = ps.getContext(ps.firstContextInStatement(ci)).start;
+ auto posb = ps.lastPositionInStatement(ci);
+ RKConsole::pipeUserCommand(doc->text(KTextEditor::Range(positionToCursor(posa), positionToCursor(posb + 1))) + u'\n');
+ newpos.pos = ps.getContext(ps.nextStatement(ci)).start;
} else {
RK_DEBUG(COMMANDEDITOR, DL_WARNING, "unknown navigation commmand");
newpos.message = i18n("Unknown command <tt><b>%1</b></tt>").arg(command);
@@ -314,6 +320,7 @@ RKCodeNavigation::RKCodeNavigation(KTextEditor::View *view, QWidget *parent) : Q
QMenu *menu = new QMenu(parent);
auto action = menu->addAction(i18n("Quick Code Navigation Mode"));
action->setIcon(QIcon::fromTheme(u"debug-step-into"_s));
+ action->setWhatsThis(i18n("Step through your code using single keystrokes (<a href=\"rkward://page/rkward_code_navigation\">more info</a>)"));
menu->menuAction()->setWhatsThis(i18n("Step through your code based on its structure or enter <a href=\"rkward://page/rkward_code_navigation\">Quick Code Navigation Mode</a>"));
menu->menuAction()->setIcon(action->icon());
menu->menuAction()->setText(i18n("Code Navigation"));
@@ -339,7 +346,7 @@ RKCodeNavigation::RKCodeNavigation(KTextEditor::View *view, QWidget *parent) : Q
addAction(menu, u"rkcodenav_next"_s, i18n("Next statement"), u'n');
addAction(menu, u"rkcodenav_prev"_s, i18n("Previous statement"), u'N');
addAction(menu, u"rkcodenav_inner"_s, i18n("Next (inner) statement"), u'i');
- addAction(menu, u"rkcodenav_prev_inner"_s, i18n("Previous (inner) statement"), u'P');
+ addAction(menu, u"rkcodenav_prev_inner"_s, i18n("Previous (inner) statement"), u'I');
addAction(menu, u"rkcodenav_outer"_s, i18n("Next outer statement"), u'o');
addAction(menu, u"rkcodenav_prev_outer"_s, i18n("Previous outer statement"), u'O');
addAction(menu, u"rkcodenav_toplevel"_s, i18n("Next toplevel statement"), u't');
@@ -350,6 +357,8 @@ RKCodeNavigation::RKCodeNavigation(KTextEditor::View *view, QWidget *parent) : Q
menu->addSection(i18n("Select"));
addAction(menu, u"rkcodenav_select"_s, i18n("Select current statement"), u's');
rmdactions->addAction(addAction(menu, u"rkcodenav_select_chunk"_s, i18n("Select current code chunk"), u'S'));
+ menu->addSection(i18n("Run"));
+ addAction(menu, u"rkcodenav_run"_s, i18n("Run current statement, and advance"), u'r');
QObject::connect(menu, &QMenu::aboutToShow, this, [view, this]() {
bool rmdmode = view->document()->highlightingMode() == u"R Markdown"_s;
@@ -358,7 +367,7 @@ RKCodeNavigation::RKCodeNavigation(KTextEditor::View *view, QWidget *parent) : Q
}
QAction *RKCodeNavigation::addAction(QMenu *menu, const QString &name, const QString &label, const QChar command) {
- QAction *a = new QAction(label);
+ QAction *a = new QAction(label + u" ("_s + command + u')');
a->setObjectName(name);
QObject::connect(a, &QAction::triggered, view, [this, command]() {
if (!internal) {
More information about the rkward-tracker
mailing list