Skip to content

Commit 7cc2a5e

Browse files
committed
Replace the tab key with 4 spaces in olstoy editor
Signed-off-by: Ryan Bottriell <rbottriell@ilm.com>
1 parent 185a3a8 commit 7cc2a5e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/osltoy/codeeditor.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ CodeEditor::CodeEditor(QWidget* parent, const std::string& filename)
6868

6969

7070

71+
void
72+
CodeEditor::keyPressEvent(QKeyEvent* event)
73+
{
74+
if (event->key() == Qt::Key_Tab) {
75+
// replace the tab key with 4 spaces
76+
// TODO: make this a configurable preference?
77+
auto replacement
78+
= QKeyEvent(QEvent::KeyPress, Qt::Key_Space,
79+
Qt::KeyboardModifiers(event->nativeModifiers()),
80+
" ");
81+
QPlainTextEdit::keyPressEvent(&replacement);
82+
return;
83+
}
84+
85+
QPlainTextEdit::keyPressEvent(event);
86+
}
87+
88+
89+
7190
QFont
7291
CodeEditor::fixedFont()
7392
{

src/osltoy/codeeditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class CodeEditor final : public QPlainTextEdit {
7575
static QFont fixedFont();
7676

7777
protected:
78+
void keyPressEvent(QKeyEvent* event) override;
7879
void resizeEvent(QResizeEvent* event) override;
7980

8081
private slots:

0 commit comments

Comments
 (0)