Skip to content

Commit

Permalink
Added shortcut to duplicate lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Aug 23, 2024
1 parent 3db6d27 commit 7f49dbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
17 changes: 17 additions & 0 deletions QCodeEditor/src/internal/QCodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,23 @@ void QCodeEditor::keyPressEvent(QKeyEvent* e) {
return;
}

// Duplicate line
if (e->key() == Qt::Key_D &&
(e->modifiers() & Qt::ControlModifier) &&
(e->modifiers() & Qt::ShiftModifier)) {
auto tc = textCursor();
auto linepos = tc.positionInBlock();
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
tc.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
auto line = tc.selectedText();
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
tc.insertText(line);
tc.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor);
tc.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, linepos);
setTextCursor(tc);
return;
}

bool doSave = false;

if (e->modifiers() == Qt::ControlModifier) {
Expand Down
27 changes: 14 additions & 13 deletions pages/pagelisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,19 +703,20 @@ void PageLisp::on_helpButton_clicked()
"in the lisp-scripting chat at<br>"
"<a href=\"https://discord.gg/JgvV5NwYts\">https://discord.gg/JgvV5NwYts</a><br><br>"
"<b>Keyboard Commands</b><br>"
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected lines<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Upload (and run if set) application<br>"
"Ctrl + 'w' : Stream application<br>"
"Ctrl + 'q' : Stop application<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + 'r' : Run selected block in REPL<br>";
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected lines<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Upload (and run if set) application<br>"
"Ctrl + 'w' : Stream application<br>"
"Ctrl + 'q' : Stop application<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + 'r' : Run selected block in REPL<br>"
"Ctrl + Shift + 'd' : Duplicate current line<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html);
}
Expand Down
29 changes: 15 additions & 14 deletions pages/pagescripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,21 @@ bool PageScripting::eraseQml(int size, bool reload)
void PageScripting::on_helpButton_clicked()
{
QString html = "<b>Keyboard Commands</b><br>"
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected line or block<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Run or restart embedded<br>"
"Ctrl + 'w' : Run or restart window<br>"
"Ctrl + 'q' : Stop code<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html.replace(" ","&nbsp;"));
"Ctrl + '+' : Increase font size<br>"
"Ctrl + '-' : Decrease font size<br>"
"Ctrl + space : Show auto-complete suggestions<br>"
"Ctrl + '/' : Toggle auto-comment on line or block<br>"
"Ctrl + '#' : Toggle auto-comment on line or block<br>"
"Ctrl + 'i' : Auto-indent selected line or block<br>"
"Ctrl + 'f' : Open search (and replace) bar<br>"
"Ctrl + 'e' : Run or restart embedded<br>"
"Ctrl + 'w' : Run or restart window<br>"
"Ctrl + 'q' : Stop code<br>"
"Ctrl + 'd' : Clear console<br>"
"Ctrl + 's' : Save file<br>"
"Ctrl + Shift + 'd' : Duplicate current line<br>";

HelpDialog::showHelpMonospace(this, "VESC Tool Script Editor", html);
}

void PageScripting::on_exportCArrayHwButton_clicked()
Expand Down
2 changes: 2 additions & 0 deletions res/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#### Released TBD
* Auto-save UI-state on regular intervals.
* Movable lisp-tabs and better tab behavior in general.
* Detect file system changes in script editor.
* Duplicate line shortcut in script editor.

### 6.05
#### Released 2024-08-19
Expand Down

0 comments on commit 7f49dbb

Please sign in to comment.