Bladeren bron

BUG: Fixed Console Shift+Home behavior

The console had an annoying bug: Shift+Home did not select
text up to the start of line, just jumped to the start of line
(while Shift+End already properly selected text up to the end
of line).

The problem was that Home key handling was overridden (to jump
to the end of the prompt instead of start of line) but the Shift
modifier was ignored.
Andras Lasso 10 jaren geleden
bovenliggende
commit
aaaa638b79
1 gewijzigde bestanden met toevoegingen van 12 en 1 verwijderingen
  1. 12 1
      Libs/Widgets/ctkConsole.cpp

+ 12 - 1
Libs/Widgets/ctkConsole.cpp

@@ -268,8 +268,19 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
         break;
 
       case Qt::Key_Home:
+        // Need to override the default behavior because we want to jump to right after the prompt and
+        // not to the first character in the line (beginning of the prompt).
         e->accept();
-        text_cursor.setPosition(this->InteractivePosition);
+        if (e->modifiers() & Qt::ShiftModifier)
+          {
+          // Shift+Home - SelectStartOfLine: select from the first character to the current position
+          text_cursor.setPosition(this->InteractivePosition, QTextCursor::KeepAnchor);
+          }
+        else
+          {
+          // Home - MoveToStartOfLine: jump to first character
+          text_cursor.setPosition(this->InteractivePosition);
+          }
         this->setTextCursor(text_cursor);
         break;