From 56ffdbbb29d2bb4b4942d348ba21fecdcf4e7740 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 5 Jun 2020 22:41:39 -0400 Subject: [PATCH] Correctly handle selection and opening via clicks Before we opened a link via mousePress but if we want to make a selection that will open a file and drag. Now we check if there is a selection before trying to open something. So if you click and drag a url, it will not open. If you directly click and release without dragging, it will open. FIXED-IN: 20.08 https://invent.kde.org/utilities/konsole/-/merge_requests/9 --- src/Screen.cpp | 5 +++++ src/Screen.h | 3 +++ src/TerminalDisplay.cpp | 16 +++++++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Screen.cpp b/src/Screen.cpp index 98913f59..389af4d2 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1113,6 +1113,11 @@ void Screen::clearSelection() _selBegin = -1; } +bool Screen::hasSelection() const +{ + return _selBegin != -1; +} + void Screen::getSelectionStart(int& column , int& line) const { if (_selTopLeft != -1) { diff --git a/src/Screen.h b/src/Screen.h index 01c263e5..97f25ac8 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -454,6 +454,9 @@ public: /** Clears the current selection */ void clearSelection(); + /** Return the selection state */ + bool hasSelection() const; + /** * Returns true if the character at (@p x, @p y) is part of the * current selection. diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index 895440f8..6fcee232 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -2231,15 +2231,6 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev) } else if (_usesMouseTracking && !_readOnly) { emit mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 0); } - - if ((_openLinksByDirectClick || ((ev->modifiers() & Qt::ControlModifier) != 0u))) { - auto spot = _filterChain->hotSpotAt(charLine, charColumn); - if ((spot != nullptr) && spot->type() == Filter::HotSpot::Link) { - QObject action; - action.setObjectName(QStringLiteral("open-action")); - spot->activate(&action); - } - } } } else if (ev->button() == Qt::MidButton) { processMidButtonClick(ev); @@ -2598,6 +2589,13 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev) charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 2); } + + if (!_screenWindow->screen()->hasSelection() && (_openLinksByDirectClick || ((ev->modifiers() & Qt::ControlModifier) != 0u))) { + auto spot = _filterChain->hotSpotAt(charLine, charColumn); + if ((spot != nullptr) && spot->type() == Filter::HotSpot::Link) { + spot->activate(); + } + } } void TerminalDisplay::getCharacterPosition(const QPoint& widgetPoint, int& line, int& column, bool edge) const