Commit 6635190c authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg

Allow view-controlling keys in read-only mode

Summary:
Allow to use scrolling (Shift+Up/Down/PgUp/PgDown/Home/End) and a key
for showing URL hints when the view is in read-only mode.

Test Plan:
* Prepare
  * Turn on scrollback
  * Set at least one modifier key for "Show URL hints" (edit profile → advanced)
  * Generate a few screens of text in Konsole
  * Display some URL (e.g. `echo 'www.kde.org'`)
  * Display current time every second: `while sleep 1; do printf '\r%s' "$(date)"; done`
  * Turn on read-only mode
* Patch tests
  * Scroll the view with Shift+Up/Down/PgUp/PgDown/Home/End - the view should scroll
  * Hold down URL hint key - the URL should be underlined with square and a digit on the left
  * Press <URL-hint-key>+1 - the URL should open in a web browser
* Regressions tests
  * Press different keys (including Ctrl+C, Ctrl+Z, etc; skip those mapped to Konsole actions) - nothing in terminal should happen
  * Press Ctrl+S - the time should not stop updating

Reviewers: #konsole, hindenburg

Reviewed By: #konsole, hindenburg

Subscribers: hindenburg, #konsole

Tags: #konsole

Differential Revision: https://phabricator.kde.org/D11668
parent 59228754
......@@ -1578,7 +1578,11 @@ void SessionController::updateReadOnlyActionStates()
bool SessionController::isReadOnly() const
{
if (!_session.isNull()) {
return _session->isReadOnly();
} else {
return false;
}
}
void SessionController::sessionTitleChanged()
......
......@@ -3421,12 +3421,6 @@ void TerminalDisplay::scrollScreenWindow(enum ScreenWindow::RelativeScrollMode m
void TerminalDisplay::keyPressEvent(QKeyEvent* event)
{
if (_readOnly) {
event->accept();
return;
}
if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) {
int hintSelected = event->key() - 0x31;
if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) {
......@@ -3443,6 +3437,7 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
}
}
if (!_readOnly) {
_screenWindow->screen()->setCurrentTerminalDisplay(this);
_actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't
......@@ -3456,12 +3451,15 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
}
Q_ASSERT(!_cursorBlinking);
}
}
emit keyPressedSignal(event);
#ifndef QT_NO_ACCESSIBILITY
if (!_readOnly) {
QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX());
QAccessible::updateAccessibility(&textCursorEvent);
}
#endif
event->accept();
......
......@@ -37,6 +37,7 @@
// Konsole
#include "KeyboardTranslator.h"
#include "SessionController.h"
#include "TerminalDisplay.h"
using Konsole::Vt102Emulation;
......@@ -1042,6 +1043,9 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
const Qt::KeyboardModifiers modifiers = event->modifiers();
KeyboardTranslator::States states = KeyboardTranslator::NoState;
TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
const bool isReadOnly = currentView->sessionController()->isReadOnly();
// get current states
if (getMode(MODE_NewLine)) {
states |= KeyboardTranslator::NewLineState;
......@@ -1059,6 +1063,7 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
states |= KeyboardTranslator::ApplicationKeypadState;
}
if (!isReadOnly) {
// check flow control state
if ((modifiers &Qt::ControlModifier) != 0u) {
switch (event->key()) {
......@@ -1071,6 +1076,7 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
break;
}
}
}
// look up key binding
if (_keyTranslator != nullptr) {
......@@ -1104,8 +1110,6 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
if ( entry.command() != KeyboardTranslator::NoCommand )
{
TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay();
if ((entry.command() & KeyboardTranslator::EraseCommand) != 0) {
textToSend += eraseChar();
} else if ((entry.command() & KeyboardTranslator::ScrollPageUpCommand) != 0) {
......@@ -1128,8 +1132,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
textToSend += _codec->fromUnicode(event->text());
}
if (!isReadOnly) {
emit sendData(textToSend);
} else {
}
} else if (!isReadOnly) {
// print an error message to the terminal if no key translator has been
// set
QString translatorError = i18n("No keyboard translator available. "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment