Skip to content

Commit

Permalink
Replace the tab key with 4 spaces in olstoy editor
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <[email protected]>
  • Loading branch information
rydrman committed Sep 27, 2024
1 parent 185a3a8 commit 7cc2a5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/osltoy/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ CodeEditor::CodeEditor(QWidget* parent, const std::string& filename)



void
CodeEditor::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Tab) {
// replace the tab key with 4 spaces
// TODO: make this a configurable preference?
auto replacement
= QKeyEvent(QEvent::KeyPress, Qt::Key_Space,
Qt::KeyboardModifiers(event->nativeModifiers()),
" ");
QPlainTextEdit::keyPressEvent(&replacement);
return;
}

QPlainTextEdit::keyPressEvent(event);
}



QFont
CodeEditor::fixedFont()
{
Expand Down
1 change: 1 addition & 0 deletions src/osltoy/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CodeEditor final : public QPlainTextEdit {
static QFont fixedFont();

protected:
void keyPressEvent(QKeyEvent* event) override;
void resizeEvent(QResizeEvent* event) override;

private slots:
Expand Down

0 comments on commit 7cc2a5e

Please sign in to comment.