Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the tab key with 4 spaces in olstoy editor #1875

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
" ");
Comment on lines +77 to +80
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, in most editors, does TAB do the equivalent of hitting SPACE 4 times? Or does it do the number of spaces to take you to the next 4-space boundary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'm not sure why I didn't think of that. I'll take another look when I have a moment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping just in case you're interested in fixing this up.

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
Loading