Skip to content

Commit 6d3d448

Browse files
scottfurrydanmar
authored andcommitted
Add keyboard shortcuts for CodeEditor Widget (danmar#1931)
Functionality for `copy` and `select all` text already exists as part of widget construction. Commit adds connection of those existing functions to execution with keyboard shortcuts user would normally expect. (e.g. CTRL+C for copy text) Qt does translation of keyboard shortcuts for platform (i.e. Mac OS uses command key rather than control).
1 parent 325af23 commit 6d3d448

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

gui/codeeditor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <QtWidgets>
2-
2+
#include <QShortcut>
33
#include "codeeditor.h"
44

55

@@ -200,8 +200,13 @@ CodeEditor::CodeEditor(QWidget *parent) :
200200
setObjectName("CodeEditor");
201201
setStyleSheet(generateStyleString());
202202

203+
QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this);
204+
QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this);
205+
203206
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
204207
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
208+
connect(copyText, SIGNAL(activated()), this, SLOT(copy()));
209+
connect(allText, SIGNAL(activated()), this, SLOT(selectAll()));
205210

206211
updateLineNumberAreaWidth(0);
207212
}

0 commit comments

Comments
 (0)