瀏覽代碼

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 年之前
父節點
當前提交
aaaa638b79
共有 1 個文件被更改,包括 12 次插入1 次删除
  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;