Skip to content

Commit

Permalink
changed behavior of the return key
Browse files Browse the repository at this point in the history
edit box: changed the return key to only insert a new line if at the
  end of a non-blank link (ctrl+return inserts a new line regardless)
removed the creation of a new key press ctrl+return event because it
  doesn't work with the new return key check; instead just insert the
  new line character directly
  • Loading branch information
thunder422 committed Jan 25, 2013
1 parent 241fa39 commit 2915908
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions editbox.cpp
Expand Up @@ -46,16 +46,22 @@ EditBox::EditBox(QWidget *parent) :

void EditBox::keyPressEvent(QKeyEvent *event)
{
QTextCursor cursor = textCursor();

switch (event->key())
{
case Qt::Key_Return:
case Qt::Key_Enter:
// intercept Control+Return and change it to a Return event
if (event->modifiers() & Qt::ControlModifier)
{
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Return,
Qt::NoModifier);
QApplication::postEvent(this, event);
cursor.insertText("\n");
return;
}
// intercept Return when cursor is not at the end of a line
if (!cursor.atBlockEnd() || cursor.atBlockStart())
{
moveCursor(QTextCursor::NextBlock);
return;
}
break;
Expand Down

0 comments on commit 2915908

Please sign in to comment.