Skip to content

Commit

Permalink
GUI - M-; to toggle line comments
Browse files Browse the repository at this point in the history
  • Loading branch information
minivan committed Aug 6, 2015
1 parent d91b760 commit dde71bb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ MainWindow::MainWindow(QApplication &app, bool i18n, QSplashScreen* splash)
QShortcut *cutToBuffer = new QShortcut(ctrlKey(']'), workspace);
connect(cutToBuffer, SIGNAL(activated()), workspace, SLOT(cut()));

//comment line
QShortcut *toggleLineComment= new QShortcut(metaKey(';'), workspace);
connect(toggleLineComment, SIGNAL(activated()), workspace, SLOT(toggleComment()));

//upcase next word
QShortcut *upcaseWord= new QShortcut(metaKey('u'), workspace);
connect(upcaseWord, SIGNAL(activated()), workspace, SLOT(upcaseWordOrSelection()));
Expand Down
32 changes: 32 additions & 0 deletions app/gui/qt/sonicpiscintilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,38 @@ void SonicPiScintilla::moveLines(int numLines) {
}
}

void SonicPiScintilla::toggleComment() {
beginUndoAction();

int linenum, cursor;
getCursorPosition(&linenum, &cursor);

//select the whole line
setSelection(linenum, 0, linenum, cursor+1);

QString selection = selectedText();

// make sure we don't comment empty lines
if (selection.length() > 0) {
// if it's already commented, uncomment
if (selection[0] == '#') {
selection.remove(0, 1);
replaceSelectedText(selection);
if (cursor > 0) {
setCursorPosition(linenum, cursor - 1);
} else {
setCursorPosition(linenum, cursor);
}
} else {
selection.prepend('#');
replaceSelectedText(selection);
setCursorPosition(linenum, cursor + 1);
}
}
deselect();
endUndoAction();
}

void SonicPiScintilla::upcaseWordOrSelection(){
if(hasSelectedText()) {
SendScintilla(SCI_UPPERCASE);
Expand Down
1 change: 1 addition & 0 deletions app/gui/qt/sonicpiscintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SonicPiScintilla : public QsciScintilla
int incLineNumWithinBounds(int linenum, int inc);
void moveLines(int numLines);
void deselect();
void toggleComment();
void upcaseWordOrSelection();
void downcaseWordOrSelection();
void highlightAll();
Expand Down
1 change: 1 addition & 0 deletions etc/doc/tutorial/en/10.2-Shortcut-Cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Windows/Linux or *Cmd* on Mac):
* `M-m` - Align all text
* `Tab` - Align current line/selection (or complete list)
* `C-l` - Centre editor
* `M-;` - Comment/Uncomment current line
* `C-t` - Transpose/swap characters
* `M-u` - Convert next word (or selection) to upper case.
* `M-l` - Convert next word (or selection) to lower case.
Expand Down

0 comments on commit dde71bb

Please sign in to comment.