Skip to content

Commit

Permalink
adjusted return behavior, corrected when there is a selection
Browse files Browse the repository at this point in the history
previously, a return key only inserted a new line when at the end of a
non-blank line (use control+return key to always insert a new line);
adjusted behavior to also insert a new line on a blank line

when there was a selection, a return key ignored the selection an
advanced to the next line; this was corrected to replace the selected
text with a new line

when there was a selection across two lines with characters selected on
the second line, a control+return key correctly replaced the selection
with a new line, however, the edit box was not redrawn properly (the
selection remained on the screen, though text was not actually selected
and the text was removed from the document); this was corrected by
creating a new key press event with a no modified return key
  • Loading branch information
thunder422 committed Mar 8, 2013
1 parent 53bf17f commit a8b9f09
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions editbox.cpp
Expand Up @@ -82,16 +82,21 @@ void EditBox::keyPressEvent(QKeyEvent *event)
case Qt::Key_Return:
case Qt::Key_Enter:
// intercept Control+Return and change it to a Return event
if (event->modifiers() & Qt::ControlModifier
|| cursor.atBlockEnd() && !cursor.atBlockStart())
if (event->modifiers() & Qt::ControlModifier || cursor.atBlockEnd())
{
cursor.insertText("\n");
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Return,
Qt::NoModifier);
QPlainTextEdit::keyPressEvent(event);
delete event;
return;
}
else // intercept Return when cursor is not at the end of a line
{
moveCursor(QTextCursor::NextBlock);
return;
if (!cursor.hasSelection())
{
moveCursor(QTextCursor::NextBlock);
return;
}
}
break;

Expand Down

0 comments on commit a8b9f09

Please sign in to comment.