summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Tillmanns <marcus.tillmanns@qt.io>2023-03-06 12:25:26 +0100
committerMarcus Tillmanns <marcus.tillmanns@qt.io>2023-03-09 19:56:48 +0000
commit665ae04605cfa4033201b42194580b32739c9df9 (patch)
treef25232e355d1cd5071940b77e043ff76733272dd
parent7a2bd0898d78a5031297ab5d6784fbaa021840d0 (diff)
downloadqt-creator-665ae04605cfa4033201b42194580b32739c9df9.tar.gz
Terminal: Open Link with line/column info
Change-Id: I3e70a7c33a935b7bd3e12fb903148bcd60ff55aa Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
-rw-r--r--src/libs/utils/link.h6
-rw-r--r--src/plugins/terminal/terminalwidget.cpp23
-rw-r--r--src/plugins/terminal/terminalwidget.h5
-rwxr-xr-xsrc/plugins/terminal/tests/filenames22
4 files changed, 43 insertions, 13 deletions
diff --git a/src/libs/utils/link.h b/src/libs/utils/link.h
index 655957e9ac..00194654c9 100644
--- a/src/libs/utils/link.h
+++ b/src/libs/utils/link.h
@@ -27,7 +27,11 @@ public:
static Link fromString(const QString &filePathWithNumbers, bool canContainLineNumber = false);
bool hasValidTarget() const
- { return !targetFilePath.isEmpty(); }
+ {
+ if (!targetFilePath.isEmpty())
+ return true;
+ return !targetFilePath.scheme().isEmpty() || !targetFilePath.host().isEmpty();
+ }
bool hasValidLinkText() const
{ return linkTextStart != linkTextEnd; }
diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp
index f2af06d577..8df6e3c02a 100644
--- a/src/plugins/terminal/terminalwidget.cpp
+++ b/src/plugins/terminal/terminalwidget.cpp
@@ -3,7 +3,6 @@
#include "terminalwidget.h"
#include "glyphcache.h"
-#include "keys.h"
#include "terminalsettings.h"
#include "terminalsurface.h"
#include "terminaltr.h"
@@ -993,11 +992,12 @@ void TerminalWidget::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) {
if (m_linkSelection) {
- if (m_linkSelection->filePath.scheme().toString().startsWith("http")) {
- QDesktopServices::openUrl(m_linkSelection->filePath.toUrl());
+ if (m_linkSelection->link.targetFilePath.scheme().toString().startsWith("http")) {
+ QDesktopServices::openUrl(m_linkSelection->link.targetFilePath.toUrl());
return;
}
- Core::EditorManager::openEditorAt(Utils::Link(m_linkSelection->filePath));
+
+ Core::EditorManager::openEditorAt(m_linkSelection->link);
}
return;
}
@@ -1062,17 +1062,20 @@ void TerminalWidget::checkLinkAt(const QPoint &pos)
const TextAndOffsets hit = textAt(pos);
if (hit.text.size() > 0) {
- QString t = QString::fromUcs4(hit.text.c_str(), hit.text.size());
+ QString t
+ = Utils::chopIfEndsWith(QString::fromUcs4(hit.text.c_str(), hit.text.size()).trimmed(),
+ ':');
if (t.startsWith("~/")) {
t = QDir::homePath() + t.mid(1);
}
- // Todo: Windows path support
- const FilePath p = FilePath::fromString(t.trimmed());
+ Utils::Link link = Utils::Link::fromString(t, true);
- if (!p.isEmpty() && (p.scheme().toString().startsWith("http") || p.exists())) {
- const LinkSelection newSelection = LinkSelection{{hit.start, hit.end}, p};
- if (*m_linkSelection != newSelection) {
+ if (link.hasValidTarget()
+ && (link.targetFilePath.scheme().toString().startsWith("http")
+ || link.targetFilePath.exists())) {
+ const LinkSelection newSelection = LinkSelection{{hit.start, hit.end}, link};
+ if (!m_linkSelection || *m_linkSelection != newSelection) {
m_linkSelection = newSelection;
updateViewport();
}
diff --git a/src/plugins/terminal/terminalwidget.h b/src/plugins/terminal/terminalwidget.h
index 07355b95bc..6238fac52c 100644
--- a/src/plugins/terminal/terminalwidget.h
+++ b/src/plugins/terminal/terminalwidget.h
@@ -5,6 +5,7 @@
#include "terminalsurface.h"
+#include <utils/link.h>
#include <utils/qtcprocess.h>
#include <utils/terminalhooks.h>
@@ -59,11 +60,11 @@ public:
struct LinkSelection : public Selection
{
- Utils::FilePath filePath;
+ Utils::Link link;
bool operator!=(const LinkSelection &other) const
{
- return filePath != other.filePath || Selection::operator!=(other);
+ return link != other.link || Selection::operator!=(other);
}
};
diff --git a/src/plugins/terminal/tests/filenames b/src/plugins/terminal/tests/filenames
new file mode 100755
index 0000000000..6a4e33e3ed
--- /dev/null
+++ b/src/plugins/terminal/tests/filenames
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+echo "Home:"
+echo "~/"
+
+FULLPATH=$(readlink -f "$0")
+
+echo "This file:"
+echo "$FULLPATH"
+
+echo "This file, this line:"
+echo "$FULLPATH:11"
+
+echo "This file, this line, this word:"
+echo "$FULLPATH:14:34"
+
+echo "This file, with an error message:"
+echo "$FULLPATH:18:23: error: C++ requires a type specifier for all declarations"
+
+echo "A link: http://google.com"
+echo "Another link: https://www.qt.io"
+echo "Another one: https://codereview.qt-project.org/c/qt-creator/qt-creator/+/464740"