diff --git a/lib/Emulation.cpp b/lib/Emulation.cpp index e599b21..001d15b 100644 --- a/lib/Emulation.cpp +++ b/lib/Emulation.cpp @@ -112,6 +112,8 @@ ScreenWindow* Emulation::createWindow() connect(this, &Emulation::handleCommandFromKeyboard, window, &ScreenWindow::handleCommandFromKeyboard); + connect(this, &Emulation::outputFromKeypressEvent, + window, &ScreenWindow::scrollToEnd); return window; } @@ -210,7 +212,7 @@ void Emulation::receiveChar(wchar_t c) }; } -void Emulation::sendKeyEvent( QKeyEvent* ev ) +void Emulation::sendKeyEvent(QKeyEvent* ev, bool) { emit stateSet(NOTIFYNORMAL); diff --git a/lib/Emulation.h b/lib/Emulation.h index 4bb6a97..7d2263b 100644 --- a/lib/Emulation.h +++ b/lib/Emulation.h @@ -253,7 +253,7 @@ public slots: * Interprets a key press event and emits the sendData() signal with * the resulting character stream. */ - virtual void sendKeyEvent(QKeyEvent*); + virtual void sendKeyEvent(QKeyEvent*, bool fromPaste); /** * Converts information about a mouse event into an xterm-compatible escape @@ -443,6 +443,7 @@ signals: void cursorChanged(KeyboardCursorShape cursorShape, bool blinkingCursorEnabled); void handleCommandFromKeyboard(KeyboardTranslator::Command command); + void outputFromKeypressEvent(void); protected: virtual void setMode(int mode) = 0; diff --git a/lib/Session.cpp b/lib/Session.cpp index 98f2bbe..faec5e7 100644 --- a/lib/Session.cpp +++ b/lib/Session.cpp @@ -174,8 +174,8 @@ void Session::addView(TerminalDisplay * widget) if ( _emulation != nullptr ) { // connect emulation - view signals and slots - connect( widget , SIGNAL(keyPressedSignal(QKeyEvent *)) , _emulation , - SLOT(sendKeyEvent(QKeyEvent *)) ); + connect( widget , &TerminalDisplay::keyPressedSignal, _emulation , + &Emulation::sendKeyEvent); connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , SLOT(sendMouseEvent(int,int,int,int)) ); connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation , @@ -567,7 +567,7 @@ void Session::sendText(const QString & text) const void Session::sendKeyEvent(QKeyEvent* e) const { - _emulation->sendKeyEvent(e); + _emulation->sendKeyEvent(e, false); } Session::~Session() diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp index f32682a..4e427a8 100644 --- a/lib/TerminalDisplay.cpp +++ b/lib/TerminalDisplay.cpp @@ -2513,7 +2513,7 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev ) QKeyEvent keyScrollEvent(QEvent::KeyPress,key,Qt::NoModifier); for (int i=0;iclearSelection(); + + switch(mMotionAfterPasting) + { + case MoveStartScreenWindow: + // Temporarily stop tracking output, or pasting contents triggers + // ScreenWindow::notifyOutputChanged() and the latter scrolls the + // terminal to the last line. It will be re-enabled when needed + // (e.g., scrolling to the last line). + _screenWindow->setTrackOutput(false); + _screenWindow->scrollTo(0); + break; + case MoveEndScreenWindow: + scrollToEnd(); + break; + case NoMoveScreenWindow: + break; + } } } @@ -2736,8 +2753,6 @@ int TerminalDisplay::motionAfterPasting() void TerminalDisplay::keyPressEvent( QKeyEvent* event ) { - bool emitKeyPressSignal = true; - _actSel=0; // Key stroke implies a screen update, so TerminalDisplay won't // know where the current selection is. @@ -2750,31 +2765,7 @@ void TerminalDisplay::keyPressEvent( QKeyEvent* event ) _cursorBlinking = false; } - if ( emitKeyPressSignal ) - { - emit keyPressedSignal(event); - - if(event->modifiers().testFlag(Qt::ShiftModifier) - || event->modifiers().testFlag(Qt::ControlModifier) - || event->modifiers().testFlag(Qt::AltModifier)) - { - switch(mMotionAfterPasting) - { - case MoveStartScreenWindow: - _screenWindow->scrollTo(0); - break; - case MoveEndScreenWindow: - scrollToEnd(); - break; - case NoMoveScreenWindow: - break; - } - } - else - { - scrollToEnd(); - } - } + emit keyPressedSignal(event, false); event->accept(); } @@ -2782,7 +2773,7 @@ void TerminalDisplay::keyPressEvent( QKeyEvent* event ) void TerminalDisplay::inputMethodEvent( QInputMethodEvent* event ) { QKeyEvent keyEvent(QEvent::KeyPress,0,Qt::NoModifier,event->commitString()); - emit keyPressedSignal(&keyEvent); + emit keyPressedSignal(&keyEvent, false); _inputMethodData.preeditString = event->preeditString().toStdWString(); update(preeditRect() | _inputMethodData.previousPreeditRect); diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h index 40ce3e0..fabf1b1 100644 --- a/lib/TerminalDisplay.h +++ b/lib/TerminalDisplay.h @@ -521,7 +521,7 @@ signals: /** * Emitted when the user presses a key whilst the terminal widget has focus. */ - void keyPressedSignal(QKeyEvent *e); + void keyPressedSignal(QKeyEvent *e, bool fromPaste); /** * A mouse event occurred. diff --git a/lib/Vt102Emulation.cpp b/lib/Vt102Emulation.cpp index 85febc4..be41cc4 100644 --- a/lib/Vt102Emulation.cpp +++ b/lib/Vt102Emulation.cpp @@ -1016,10 +1016,10 @@ void Vt102Emulation::sendText( const QString& text ) 0, Qt::NoModifier, text); - sendKeyEvent(&event); // expose as a big fat keypress event + sendKeyEvent(&event, false); // expose as a big fat keypress event } } -void Vt102Emulation::sendKeyEvent( QKeyEvent* event ) +void Vt102Emulation::sendKeyEvent(QKeyEvent* event, bool fromPaste) { Qt::KeyboardModifiers modifiers = event->modifiers(); KeyboardTranslator::States states = KeyboardTranslator::NoState; @@ -1107,6 +1107,9 @@ void Vt102Emulation::sendKeyEvent( QKeyEvent* event ) textToSend += _codec->fromUnicode(event->text()); } + if (!fromPaste && textToSend.length()) { + Q_EMIT outputFromKeypressEvent(); + } Q_EMIT sendData( textToSend.constData() , textToSend.length() ); } else diff --git a/lib/Vt102Emulation.h b/lib/Vt102Emulation.h index 99c98e2..214e50c 100644 --- a/lib/Vt102Emulation.h +++ b/lib/Vt102Emulation.h @@ -93,7 +93,7 @@ public slots: // reimplemented from Emulation void sendString(const char*,int length = -1) override; void sendText(const QString& text) override; - void sendKeyEvent(QKeyEvent*) override; + void sendKeyEvent(QKeyEvent*, bool fromPaste) override; void sendMouseEvent(int buttons, int column, int line, int eventType) override; virtual void focusLost(); virtual void focusGained(); diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp index 594a44a..9d692ea 100644 --- a/lib/qtermwidget.cpp +++ b/lib/qtermwidget.cpp @@ -328,8 +328,8 @@ void QTermWidget::init(int startnow) this, SIGNAL(termGetFocus())); connect(m_impl->m_terminalDisplay, SIGNAL(termLostFocus()), this, SIGNAL(termLostFocus())); - connect(m_impl->m_terminalDisplay, SIGNAL(keyPressedSignal(QKeyEvent *)), - this, SIGNAL(termKeyPressed(QKeyEvent *))); + connect(m_impl->m_terminalDisplay, &TerminalDisplay::keyPressedSignal, + [this] (QKeyEvent* e, bool) { Q_EMIT termKeyPressed(e); }); // m_impl->m_terminalDisplay->setSize(80, 40); QFont font = QApplication::font();