Skip to content

Commit 71be81b

Browse files
committed
Tab key Bug Fix
1 parent f7d1eb8 commit 71be81b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

CodeEditor/codeeditor.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ void CodeEditor::keyPressEvent(QKeyEvent* e)
173173
}
174174
break;
175175
case Qt::Key_Tab:
176-
SelectLineMarginBlock();
177-
{
178-
QString text("");
179-
QStringList lines = this->textCursor().selection().toPlainText().split(QRegExp("\n|\r\n|\r"));
180-
foreach (QString line, lines) {
181-
text.append(" ");
182-
text.append(line);
183-
text.append("\n");
176+
if (this->textCursor().hasSelection()) {
177+
SelectLineMarginBlock();
178+
{
179+
QString text("");
180+
QStringList lines = this->textCursor().selection().toPlainText().split(QRegExp("\n|\r\n|\r"));
181+
foreach (QString line, lines) {
182+
text.append(" ");
183+
text.append(line);
184+
text.append("\n");
185+
}
186+
text.truncate(text.length() - 1);
187+
this->textCursor().insertText(text);
184188
}
185-
text.truncate(text.length() - 1);
186-
this->textCursor().insertText(text);
189+
} else {
190+
this->insertPlainText(" ");
187191
}
188192
break;
189193
case Qt::Key_Enter:

0 commit comments

Comments
 (0)