aboutsummaryrefslogtreecommitdiffstats
path: root/community/kate/ctrl-click.patch
diff options
context:
space:
mode:
Diffstat (limited to 'community/kate/ctrl-click.patch')
-rw-r--r--community/kate/ctrl-click.patch973
1 files changed, 0 insertions, 973 deletions
diff --git a/community/kate/ctrl-click.patch b/community/kate/ctrl-click.patch
deleted file mode 100644
index 107abc9bfe..0000000000
--- a/community/kate/ctrl-click.patch
+++ /dev/null
@@ -1,973 +0,0 @@
-From b76ec6615928d103d67399de046a35b6289124bc Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 18:39:00 +0500
-Subject: [PATCH 01/12] LSP: Allow to go to definition using Ctrl + Click
-
----
- addons/lspclient/lspclientpluginview.cpp | 122 ++++++++++++++++++++++-
- 1 file changed, 119 insertions(+), 3 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 78e806fd5..e7942b1fb 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -283,6 +283,8 @@ class LSPClientActionView : public QObject
- // characters to trigger format request
- QVector<QChar> m_onTypeFormattingTriggers;
-
-+ QWidget* cursorChangeWid = nullptr;
-+
- KActionCollection *actionCollection() const
- {
- return m_client->actionCollection();
-@@ -462,10 +464,88 @@ public:
- m_viewTracker.reset(LSPClientViewTracker::new_(plugin, mainWin, 0, 500));
- connect(m_viewTracker.data(), &LSPClientViewTracker::newState, this, &self_type::onViewState);
-
-+ connect(m_mainWindow, &KTextEditor::MainWindow::viewCreated, this, &LSPClientActionView::onViewCreated);
-+
-+ connect(this, &LSPClientActionView::ctrlClickDefRecieved, this, &LSPClientActionView::onCtrlMouseMove);
-+
- configUpdated();
- updateState();
- }
-
-+ void onViewCreated(KTextEditor::View *view)
-+ {
-+ if (view) {
-+ view->installEventFilter(this);
-+ auto childs = view->children();
-+ for (auto c : childs) {
-+ if (c)
-+ c->installEventFilter(this);
-+ }
-+ }
-+ }
-+
-+ // taken from KDevelop :)
-+ KTextEditor::View* viewFromWidget(QWidget* widget)
-+ {
-+ if (!widget)
-+ return nullptr;
-+ auto* view = qobject_cast<KTextEditor::View*>(widget);
-+ if (view)
-+ return view;
-+ else
-+ return viewFromWidget(widget->parentWidget());
-+ }
-+
-+ bool eventFilter(QObject* obj, QEvent* event) override {
-+ auto mouseEvent = dynamic_cast<QMouseEvent*>(event);
-+
-+ if (mouseEvent) {
-+ // common stuff that we need for both events
-+ auto wid = qobject_cast<QWidget*>(obj);
-+ auto v = viewFromWidget(wid);
-+ if (!v)
-+ return false;
-+
-+ const auto coords = wid->mapTo(v, mouseEvent->pos());
-+ const auto cur = v->coordinatesToCursor(coords);
-+ const auto word = v->document()->wordAt(cur);
-+
-+ // The user pressed Ctrl + Click
-+ if (event->type() == QEvent::MouseButtonPress) {
-+ if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
-+ // must set cursor else we will be jumping somewhere else!!
-+ v->setCursorPosition(cur);
-+ if (!word.isEmpty()) {
-+ cursorChangeWid = nullptr;
-+ goToDefinition();
-+ }
-+ }
-+ }
-+ // The user is hovering with Ctrl pressed
-+ else if (event->type() == QEvent::MouseMove) {
-+ if (mouseEvent->modifiers() == Qt::ControlModifier) {
-+ if (!word.isEmpty()) {
-+ cursorChangeWid = wid;
-+ // this will not go anywhere actually, but just signal whether we have a definition
-+ // Also, please rethink very hard if you are going to reuse this method. It's made
-+ // only for Ctrl+Hover
-+ processCtrlMouseHover(cur);
-+ } else {
-+ // if there is no word, unset the cursor
-+ if (wid)
-+ wid->unsetCursor();
-+ }
-+ } else {
-+ // simple mouse move, make sure to unset the cursor
-+ if (wid)
-+ wid->unsetCursor();
-+ }
-+ }
-+ }
-+
-+ return false;
-+ }
-+
- ~LSPClientActionView() override
- {
- // unregister all code-completion providers, else we might crash
-@@ -700,7 +780,6 @@ public:
- }
-
- // add match mark for range
-- const int ps = 32;
- bool handleClick = true;
- enabled = m_diagnostics && m_diagnostics->isChecked() && m_diagnosticsMark && m_diagnosticsMark->isChecked();
- switch (markType) {
-@@ -948,6 +1027,11 @@ public:
- QUrl uri;
- LSPRange range;
- LSPDocumentHighlightKind kind;
-+
-+ bool isValid() const
-+ {
-+ return uri.isValid() && range.isValid();
-+ }
- };
-
- static bool compareRangeItem(const RangeItem &a, const RangeItem &b)
-@@ -1126,7 +1210,7 @@ public:
-
- template<typename Handler> using LocationRequest = std::function<LSPClientServer::RequestHandle(LSPClientServer &, const QUrl &document, const LSPPosition &pos, const QObject *context, const Handler &h)>;
-
-- template<typename Handler> void positionRequest(const LocationRequest<Handler> &req, const Handler &h, QScopedPointer<LSPClientRevisionSnapshot> *snapshot = nullptr)
-+ template<typename Handler> void positionRequest(const LocationRequest<Handler> &req, const Handler &h, QScopedPointer<LSPClientRevisionSnapshot> *snapshot = nullptr, KTextEditor::Cursor cur = KTextEditor::Cursor(-1, -1))
- {
- KTextEditor::View *activeView = m_mainWindow->activeView();
- auto server = m_serverManager->findServer(activeView);
-@@ -1138,7 +1222,7 @@ public:
- snapshot->reset(m_serverManager->snapshot(server.data()));
- }
-
-- KTextEditor::Cursor cursor = activeView->cursorPosition();
-+ KTextEditor::Cursor cursor = cur.isValid() ? cur : activeView->cursorPosition();
-
- clearAllLocationMarks();
- m_req_timeout = false;
-@@ -1157,6 +1241,16 @@ public:
- }
- }
-
-+ Q_SIGNAL void ctrlClickDefRecieved(const RangeItem& range);
-+
-+ Q_SLOT void onCtrlMouseMove(const RangeItem& range)
-+ {
-+ if (range.isValid()) {
-+ if (cursorChangeWid)
-+ cursorChangeWid->setCursor(Qt::PointingHandCursor);
-+ }
-+ }
-+
- // some template and function type trickery here, but at least that buck stops here then ...
- template<typename ReplyEntryType, bool doshow = true, typename HandlerType = ReplyHandler<QList<ReplyEntryType>>>
- void processLocations(const QString &title,
-@@ -1206,6 +1300,28 @@ public:
- positionRequest<HandlerType>(req, h, s.data());
- }
-
-+ /**
-+ * @brief processCtrlMouseHover This function just processes Ctrl + Mouse move hovering.
-+ * It should not be used for other purposes ideally.
-+ */
-+ void processCtrlMouseHover(const KTextEditor::Cursor& cursor)
-+ {
-+ auto h = [this](const QList<LSPLocation> &defs) {
-+ if (defs.isEmpty()) {
-+ return;
-+ } else {
-+ const auto item = locationToRangeItem(defs.at(0));
-+ emit this->ctrlClickDefRecieved(item);
-+ return;
-+ }
-+ };
-+
-+ using Handler = std::function<void(const QList<LSPLocation> &)>;
-+ auto request = &LSPClientServer::documentDefinition;
-+ positionRequest<Handler>(request, h, nullptr, cursor);
-+ }
-+
-+
- static RangeItem locationToRangeItem(const LSPLocation &loc)
- {
- return {loc.uri, loc.range, LSPDocumentHighlightKind::Text};
---
-GitLab
-
-
-From 8a7ff9768be3734e722685971042c97a2bc3093f Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 20:28:03 +0500
-Subject: [PATCH 02/12] LSP: Show underline on Ctrl+MouseMove when a symbol is
- goto-able
-
-BUG: 427267
----
- addons/lspclient/lspclientpluginview.cpp | 74 +++++++++++++++++++++---
- 1 file changed, 67 insertions(+), 7 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index e7942b1fb..97a2e2b7c 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -189,6 +189,61 @@ public:
- }
- };
-
-+
-+/**
-+ * @brief This is just a helper class that provides "underline" on Ctrl + click
-+ */
-+struct CtrlHoverFeedback
-+{
-+public:
-+
-+ void highlight(KTextEditor::View* activeView)
-+ {
-+ if (w)
-+ w->setCursor(Qt::PointingHandCursor);
-+ if (activeView) {
-+ if (mr) {
-+ mr->setRange(range);
-+ } else {
-+ auto miface = qobject_cast<KTextEditor::MovingInterface*>(activeView->document());
-+ if (!miface)
-+ return;
-+ mr.reset(miface->newMovingRange(range));
-+ }
-+
-+ static KTextEditor::Attribute::Ptr attr;
-+ if (!attr) {
-+ attr = new KTextEditor::Attribute;
-+ attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
-+ }
-+ mr->setAttribute(attr);
-+ }
-+ }
-+
-+ void clear()
-+ {
-+ if (mr) {
-+ mr->setRange({-1,-1,-1,-1});
-+ }
-+ }
-+
-+ void setRangeAndWidget(const KTextEditor::Range& r, QWidget* wid)
-+ {
-+ range = r;
-+ w = wid;
-+ }
-+
-+ bool isValid() const
-+ {
-+ return w != nullptr;
-+ }
-+
-+private:
-+ QWidget* w = nullptr;
-+ std::unique_ptr<KTextEditor::MovingRange> mr;
-+ KTextEditor::Range range;
-+};
-+
- class LSPClientActionView : public QObject
- {
- Q_OBJECT
-@@ -283,7 +338,7 @@ class LSPClientActionView : public QObject
- // characters to trigger format request
- QVector<QChar> m_onTypeFormattingTriggers;
-
-- QWidget* cursorChangeWid = nullptr;
-+ CtrlHoverFeedback m_ctrlHoverFeedback = {};
-
- KActionCollection *actionCollection() const
- {
-@@ -484,7 +539,7 @@ public:
- }
- }
-
-- // taken from KDevelop :)
-+ // This is taken from KDevelop :)
- KTextEditor::View* viewFromWidget(QWidget* widget)
- {
- if (!widget)
-@@ -516,7 +571,7 @@ public:
- // must set cursor else we will be jumping somewhere else!!
- v->setCursorPosition(cur);
- if (!word.isEmpty()) {
-- cursorChangeWid = nullptr;
-+ m_ctrlHoverFeedback.clear();
- goToDefinition();
- }
- }
-@@ -524,8 +579,11 @@ public:
- // The user is hovering with Ctrl pressed
- else if (event->type() == QEvent::MouseMove) {
- if (mouseEvent->modifiers() == Qt::ControlModifier) {
-- if (!word.isEmpty()) {
-- cursorChangeWid = wid;
-+ auto doc = v->document();
-+ const auto hoveredWord = doc->wordAt(cur);
-+ const auto range = doc->wordRangeAt(cur);
-+ if (!hoveredWord.isEmpty() && range.isValid()) {
-+ m_ctrlHoverFeedback.setRangeAndWidget(range, wid);
- // this will not go anywhere actually, but just signal whether we have a definition
- // Also, please rethink very hard if you are going to reuse this method. It's made
- // only for Ctrl+Hover
-@@ -534,11 +592,13 @@ public:
- // if there is no word, unset the cursor
- if (wid)
- wid->unsetCursor();
-+ m_ctrlHoverFeedback.clear();
- }
- } else {
- // simple mouse move, make sure to unset the cursor
- if (wid)
- wid->unsetCursor();
-+ m_ctrlHoverFeedback.clear();
- }
- }
- }
-@@ -1246,8 +1306,8 @@ public:
- Q_SLOT void onCtrlMouseMove(const RangeItem& range)
- {
- if (range.isValid()) {
-- if (cursorChangeWid)
-- cursorChangeWid->setCursor(Qt::PointingHandCursor);
-+ if (m_ctrlHoverFeedback.isValid())
-+ m_ctrlHoverFeedback.highlight(m_mainWindow->activeView());
- }
- }
-
---
-GitLab
-
-
-From 2cf05fc379f29e5c70f15c6625e4a6b3ee3f2ed2 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 21:38:11 +0500
-Subject: [PATCH 03/12] Make Ctrl+Click underlining work for multiple opened
- docs
-
----
- addons/lspclient/lspclientpluginview.cpp | 39 ++++++++++++++++++------
- 1 file changed, 30 insertions(+), 9 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 97a2e2b7c..839f1ed1e 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -193,8 +193,9 @@ public:
- /**
- * @brief This is just a helper class that provides "underline" on Ctrl + click
- */
--struct CtrlHoverFeedback
-+struct CtrlHoverFeedback : public QObject
- {
-+ Q_OBJECT
- public:
-
- void highlight(KTextEditor::View* activeView)
-@@ -202,13 +203,20 @@ public:
- if (w)
- w->setCursor(Qt::PointingHandCursor);
- if (activeView) {
-+ auto mr = ranges[activeView->document()];
- if (mr) {
- mr->setRange(range);
- } else {
- auto miface = qobject_cast<KTextEditor::MovingInterface*>(activeView->document());
- if (!miface)
- return;
-- mr.reset(miface->newMovingRange(range));
-+ auto doc = activeView->document();
-+ if (doc) {
-+ mr = miface->newMovingRange(range);
-+ ranges[doc] = mr;
-+ connect(doc, SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
-+ connect(doc, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
-+ }
- }
-
- static KTextEditor::Attribute::Ptr attr;
-@@ -220,10 +228,15 @@ public:
- }
- }
-
-- void clear()
-+ void clear(KTextEditor::View* activeView)
- {
-- if (mr) {
-- mr->setRange({-1,-1,-1,-1});
-+ if (activeView) {
-+ auto doc = activeView->document();
-+ if (doc) {
-+ auto& mr = ranges[doc];
-+ if (mr)
-+ mr->setRange({-1,-1,-1,-1});
-+ }
- }
- }
-
-@@ -238,9 +251,17 @@ public:
- return w != nullptr;
- }
-
-+private:
-+
-+ Q_SLOT void clear(KTextEditor::Document* doc)
-+ {
-+ if (doc)
-+ delete ranges[doc];
-+ }
-+
- private:
- QWidget* w = nullptr;
-- std::unique_ptr<KTextEditor::MovingRange> mr;
-+ QHash<KTextEditor::Document*, KTextEditor::MovingRange*> ranges;
- KTextEditor::Range range;
- };
-
-@@ -571,7 +592,7 @@ public:
- // must set cursor else we will be jumping somewhere else!!
- v->setCursorPosition(cur);
- if (!word.isEmpty()) {
-- m_ctrlHoverFeedback.clear();
-+ m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
- goToDefinition();
- }
- }
-@@ -592,13 +613,13 @@ public:
- // if there is no word, unset the cursor
- if (wid)
- wid->unsetCursor();
-- m_ctrlHoverFeedback.clear();
-+ m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
- }
- } else {
- // simple mouse move, make sure to unset the cursor
- if (wid)
- wid->unsetCursor();
-- m_ctrlHoverFeedback.clear();
-+ m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
- }
- }
- }
---
-GitLab
-
-
-From d5f1eacb1c7611de57a0245af4e2a203ecbe005b Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 23:17:18 +0500
-Subject: [PATCH 04/12] Return early to prevent too deeply nested branches
-
----
- addons/lspclient/lspclientpluginview.cpp | 133 ++++++++++++-----------
- 1 file changed, 71 insertions(+), 62 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 839f1ed1e..cdb9981fb 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -200,32 +200,38 @@ public:
-
- void highlight(KTextEditor::View* activeView)
- {
-+ // sanity checks
-+ if (!activeView)
-+ return;
-+
-+ auto doc = activeView->document();
-+ if (!doc)
-+ return;
-+
-+ // set the cursor
- if (w)
- w->setCursor(Qt::PointingHandCursor);
-- if (activeView) {
-- auto mr = ranges[activeView->document()];
-- if (mr) {
-- mr->setRange(range);
-- } else {
-- auto miface = qobject_cast<KTextEditor::MovingInterface*>(activeView->document());
-- if (!miface)
-- return;
-- auto doc = activeView->document();
-- if (doc) {
-- mr = miface->newMovingRange(range);
-- ranges[doc] = mr;
-- connect(doc, SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
-- connect(doc, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
-- }
-- }
-
-- static KTextEditor::Attribute::Ptr attr;
-- if (!attr) {
-- attr = new KTextEditor::Attribute;
-- attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
-- }
-- mr->setAttribute(attr);
-+ // underline the hovered word
-+ auto mr = ranges[doc];
-+ if (mr) {
-+ mr->setRange(range);
-+ } else {
-+ auto miface = qobject_cast<KTextEditor::MovingInterface*>(doc);
-+ if (!miface)
-+ return;
-+ mr = miface->newMovingRange(range);
-+ ranges[doc] = mr;
-+ connect(doc, SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
-+ connect(doc, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(clear(KTextEditor::Document *)), Qt::UniqueConnection);
- }
-+
-+ static KTextEditor::Attribute::Ptr attr;
-+ if (!attr) {
-+ attr = new KTextEditor::Attribute;
-+ attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
-+ }
-+ mr->setAttribute(attr);
- }
-
- void clear(KTextEditor::View* activeView)
-@@ -235,7 +241,7 @@ public:
- if (doc) {
- auto& mr = ranges[doc];
- if (mr)
-- mr->setRange({-1,-1,-1,-1});
-+ mr->setRange(KTextEditor::Range::invalid());
- }
- }
- }
-@@ -575,52 +581,55 @@ public:
- bool eventFilter(QObject* obj, QEvent* event) override {
- auto mouseEvent = dynamic_cast<QMouseEvent*>(event);
-
-- if (mouseEvent) {
-- // common stuff that we need for both events
-- auto wid = qobject_cast<QWidget*>(obj);
-- auto v = viewFromWidget(wid);
-- if (!v)
-- return false;
--
-- const auto coords = wid->mapTo(v, mouseEvent->pos());
-- const auto cur = v->coordinatesToCursor(coords);
-- const auto word = v->document()->wordAt(cur);
--
-- // The user pressed Ctrl + Click
-- if (event->type() == QEvent::MouseButtonPress) {
-- if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
-- // must set cursor else we will be jumping somewhere else!!
-- v->setCursorPosition(cur);
-- if (!word.isEmpty()) {
-- m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
-- goToDefinition();
-- }
-+ // we are only concerned with mouse events for now :)
-+ if (!mouseEvent)
-+ return false;
-+
-+ // common stuff that we need for both events
-+ auto wid = qobject_cast<QWidget*>(obj);
-+ auto v = viewFromWidget(wid);
-+ if (!v)
-+ return false;
-+
-+ const auto coords = wid->mapTo(v, mouseEvent->pos());
-+ const auto cur = v->coordinatesToCursor(coords);
-+ const auto word = v->document()->wordAt(cur);
-+
-+ // The user pressed Ctrl + Click
-+ if (event->type() == QEvent::MouseButtonPress) {
-+ if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
-+ // must set cursor else we will be jumping somewhere else!!
-+ v->setCursorPosition(cur);
-+ if (!word.isEmpty()) {
-+ m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
-+ goToDefinition();
- }
- }
-- // The user is hovering with Ctrl pressed
-- else if (event->type() == QEvent::MouseMove) {
-- if (mouseEvent->modifiers() == Qt::ControlModifier) {
-- auto doc = v->document();
-- const auto hoveredWord = doc->wordAt(cur);
-- const auto range = doc->wordRangeAt(cur);
-- if (!hoveredWord.isEmpty() && range.isValid()) {
-- m_ctrlHoverFeedback.setRangeAndWidget(range, wid);
-- // this will not go anywhere actually, but just signal whether we have a definition
-- // Also, please rethink very hard if you are going to reuse this method. It's made
-- // only for Ctrl+Hover
-- processCtrlMouseHover(cur);
-- } else {
-- // if there is no word, unset the cursor
-- if (wid)
-- wid->unsetCursor();
-- m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
-- }
-+ }
-+ // The user is hovering with Ctrl pressed
-+ else if (event->type() == QEvent::MouseMove) {
-+ if (mouseEvent->modifiers() == Qt::ControlModifier) {
-+ auto doc = v->document();
-+ const auto hoveredWord = doc->wordAt(cur);
-+ const auto range = doc->wordRangeAt(cur);
-+ if (!hoveredWord.isEmpty() && range.isValid()) {
-+ m_ctrlHoverFeedback.setRangeAndWidget(range, wid);
-+ // this will not go anywhere actually, but just signal whether we have a definition
-+ // Also, please rethink very hard if you are going to reuse this method. It's made
-+ // only for Ctrl+Hover
-+ processCtrlMouseHover(cur);
- } else {
-- // simple mouse move, make sure to unset the cursor
-+ // if there is no word, unset the cursor and remove the highlight
- if (wid)
- wid->unsetCursor();
- m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
- }
-+ } else {
-+ // simple mouse move, make sure to unset the cursor
-+ // and remove the highlight
-+ if (wid)
-+ wid->unsetCursor();
-+ m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
- }
- }
-
---
-GitLab
-
-
-From e0ec9b3301ca0666b7671e65c961fa79638b2115 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 23:18:50 +0500
-Subject: [PATCH 05/12] Use KTextEditor::Cursor::invalid() for consistency and
- clarity
-
----
- addons/lspclient/lspclientpluginview.cpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index cdb9981fb..370d072b6 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -1300,7 +1300,7 @@ public:
-
- template<typename Handler> using LocationRequest = std::function<LSPClientServer::RequestHandle(LSPClientServer &, const QUrl &document, const LSPPosition &pos, const QObject *context, const Handler &h)>;
-
-- template<typename Handler> void positionRequest(const LocationRequest<Handler> &req, const Handler &h, QScopedPointer<LSPClientRevisionSnapshot> *snapshot = nullptr, KTextEditor::Cursor cur = KTextEditor::Cursor(-1, -1))
-+ template<typename Handler> void positionRequest(const LocationRequest<Handler> &req, const Handler &h, QScopedPointer<LSPClientRevisionSnapshot> *snapshot = nullptr, KTextEditor::Cursor cur = KTextEditor::Cursor::invalid())
- {
- KTextEditor::View *activeView = m_mainWindow->activeView();
- auto server = m_serverManager->findServer(activeView);
---
-GitLab
-
-
-From 7e0f6fcddada95fd21c9d73e7849b975ddcda9a5 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 23:20:03 +0500
-Subject: [PATCH 06/12] Change struct -> class for consistency
-
----
- addons/lspclient/lspclientpluginview.cpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 370d072b6..383b4cee0 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -193,7 +193,7 @@ public:
- /**
- * @brief This is just a helper class that provides "underline" on Ctrl + click
- */
--struct CtrlHoverFeedback : public QObject
-+class CtrlHoverFeedback : public QObject
- {
- Q_OBJECT
- public:
---
-GitLab
-
-
-From ce14e874c55a2a4fb0c53f8c55d1f937589b07d0 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 23:23:11 +0500
-Subject: [PATCH 07/12] Ensure we are working with a valid cursor always
-
----
- addons/lspclient/lspclientpluginview.cpp | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 383b4cee0..722d769c5 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -593,12 +593,15 @@ public:
-
- const auto coords = wid->mapTo(v, mouseEvent->pos());
- const auto cur = v->coordinatesToCursor(coords);
-- const auto word = v->document()->wordAt(cur);
-+ // there isn't much we can do now, just bail out
-+ if (!cur.isValid())
-+ return false;
-
- // The user pressed Ctrl + Click
- if (event->type() == QEvent::MouseButtonPress) {
- if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
- // must set cursor else we will be jumping somewhere else!!
-+ const auto word = v->document()->wordAt(cur);
- v->setCursorPosition(cur);
- if (!word.isEmpty()) {
- m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
---
-GitLab
-
-
-From 87a9e6006093826b0385254e143e6ef678917344 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Mon, 11 Jan 2021 23:33:50 +0500
-Subject: [PATCH 08/12] Dont do multiple lookup for word with the same cursor
-
----
- addons/lspclient/lspclientpluginview.cpp | 11 +++++++----
- 1 file changed, 7 insertions(+), 4 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 722d769c5..fa2f8b7e5 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -597,11 +597,16 @@ public:
- if (!cur.isValid())
- return false;
-
-+ auto doc = v->document();
-+ if (!doc)
-+ return false;
-+
-+ const auto word = doc->wordAt(cur);
-+
- // The user pressed Ctrl + Click
- if (event->type() == QEvent::MouseButtonPress) {
- if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
- // must set cursor else we will be jumping somewhere else!!
-- const auto word = v->document()->wordAt(cur);
- v->setCursorPosition(cur);
- if (!word.isEmpty()) {
- m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
-@@ -612,10 +617,8 @@ public:
- // The user is hovering with Ctrl pressed
- else if (event->type() == QEvent::MouseMove) {
- if (mouseEvent->modifiers() == Qt::ControlModifier) {
-- auto doc = v->document();
-- const auto hoveredWord = doc->wordAt(cur);
- const auto range = doc->wordRangeAt(cur);
-- if (!hoveredWord.isEmpty() && range.isValid()) {
-+ if (!word.isEmpty() && range.isValid()) {
- m_ctrlHoverFeedback.setRangeAndWidget(range, wid);
- // this will not go anywhere actually, but just signal whether we have a definition
- // Also, please rethink very hard if you are going to reuse this method. It's made
---
-GitLab
-
-
-From e691b7d77350951169723a740fe8d73682fe3ddf Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Tue, 12 Jan 2021 00:36:32 +0500
-Subject: [PATCH 09/12] Give a temporary highlight on the landed location after
- goto
-
----
- addons/lspclient/lspclientpluginview.cpp | 35 ++++++++++++++++++++----
- 1 file changed, 30 insertions(+), 5 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index fa2f8b7e5..e4ba865c5 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -955,8 +955,10 @@ public:
- addMarksRec(doc, treeModel->invisibleRootItem(), oranges, odocs);
- }
-
-- void goToDocumentLocation(const QUrl &uri, int line, int column)
-+ void goToDocumentLocation(const QUrl &uri, const KTextEditor::Range& location)
- {
-+ int line = location.start().line();
-+ int column = location.start().column();
- KTextEditor::View *activeView = m_mainWindow->activeView();
- if (!activeView || uri.isEmpty() || line < 0 || column < 0)
- return;
-@@ -966,19 +968,43 @@ public:
-
- if (document && uri == document->url()) {
- activeView->setCursorPosition(cdef);
-+ highlightLandingLocation(document, location);
- } else {
- KTextEditor::View *view = m_mainWindow->openUrl(uri);
- if (view) {
- view->setCursorPosition(cdef);
-+ highlightLandingLocation(view->document(), location);
- }
- }
- }
-
-+ /**
-+ * @brief give a short 1sec temporary highlight where you land
-+ */
-+ void highlightLandingLocation(KTextEditor::Document* doc, const KTextEditor::Range& location)
-+ {
-+ Q_ASSERT(doc);
-+ auto miface = qobject_cast<KTextEditor::MovingInterface*>(doc);
-+ if (!miface)
-+ return;
-+ auto mr = miface->newMovingRange(location);
-+ static KTextEditor::Attribute::Ptr attr;
-+ if (!attr) {
-+ attr = new KTextEditor::Attribute;
-+ attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
-+ }
-+ mr->setAttribute(attr);
-+ QTimer::singleShot(1000, this, [mr](){
-+ mr->setRange(KTextEditor::Range::invalid());
-+ delete mr;
-+ });
-+ }
-+
- void goToItemLocation(const QModelIndex &index)
- {
- auto url = index.data(RangeData::FileUrlRole).toUrl();
-- auto start = index.data(RangeData::RangeRole).value<LSPRange>().start();
-- goToDocumentLocation(url, start.line(), start.column());
-+ auto start = index.data(RangeData::RangeRole).value<LSPRange>();
-+ goToDocumentLocation(url, start);
- }
-
- // custom item subclass that captures additional attributes;
-@@ -1381,8 +1407,7 @@ public:
- if (!m_req_timeout && !onlyshow) {
- // assuming here that the first location is the best one
- const auto &item = itemConverter(defs.at(0));
-- const auto &pos = item.range.start();
-- goToDocumentLocation(item.uri, pos.line(), pos.column());
-+ goToDocumentLocation(item.uri, item.range);
- // forego mark and such if only a single destination
- if (defs.count() == 1) {
- clearAllLocationMarks();
---
-GitLab
-
-
-From 21e517ad8f3c31bba5687ea32fdfc51e0db15223 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Tue, 12 Jan 2021 01:38:07 +0500
-Subject: [PATCH 10/12] Make sure only the landed view shows the highlight
-
----
- addons/lspclient/lspclientpluginview.cpp | 11 +++++++----
- 1 file changed, 7 insertions(+), 4 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index e4ba865c5..8debbe2bb 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -968,12 +968,12 @@ public:
-
- if (document && uri == document->url()) {
- activeView->setCursorPosition(cdef);
-- highlightLandingLocation(document, location);
-+ highlightLandingLocation(activeView, location);
- } else {
- KTextEditor::View *view = m_mainWindow->openUrl(uri);
- if (view) {
- view->setCursorPosition(cdef);
-- highlightLandingLocation(view->document(), location);
-+ highlightLandingLocation(view, location);
- }
- }
- }
-@@ -981,9 +981,11 @@ public:
- /**
- * @brief give a short 1sec temporary highlight where you land
- */
-- void highlightLandingLocation(KTextEditor::Document* doc, const KTextEditor::Range& location)
-+ void highlightLandingLocation(KTextEditor::View* view, const KTextEditor::Range& location)
- {
-- Q_ASSERT(doc);
-+ auto doc = view->document();
-+ if (!doc)
-+ return;
- auto miface = qobject_cast<KTextEditor::MovingInterface*>(doc);
- if (!miface)
- return;
-@@ -993,6 +995,7 @@ public:
- attr = new KTextEditor::Attribute;
- attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
- }
-+ mr->setView(view);
- mr->setAttribute(attr);
- QTimer::singleShot(1000, this, [mr](){
- mr->setRange(KTextEditor::Range::invalid());
---
-GitLab
-
-
-From 6edfe5e88353022ceed61310bbb7570be2b7ca3a Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Tue, 12 Jan 2021 01:38:47 +0500
-Subject: [PATCH 11/12] Pass in doc instead of 'this' to ensure correct
- lifetime management
-
----
- addons/lspclient/lspclientpluginview.cpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 8debbe2bb..6761726fc 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -997,7 +997,7 @@ public:
- }
- mr->setView(view);
- mr->setAttribute(attr);
-- QTimer::singleShot(1000, this, [mr](){
-+ QTimer::singleShot(1000, doc, [mr] {
- mr->setRange(KTextEditor::Range::invalid());
- delete mr;
- });
---
-GitLab
-
-
-From a4136d7a12d61a42df25a3bc24fe01d77c87f344 Mon Sep 17 00:00:00 2001
-From: Waqar Ahmed <waqar.17a@gmail.com>
-Date: Tue, 12 Jan 2021 01:46:13 +0500
-Subject: [PATCH 12/12] Dont use static for attribute as it is unnecessary
-
----
- addons/lspclient/lspclientpluginview.cpp | 7 ++-----
- 1 file changed, 2 insertions(+), 5 deletions(-)
-
-diff --git a/addons/lspclient/lspclientpluginview.cpp b/addons/lspclient/lspclientpluginview.cpp
-index 6761726fc..794dfd0c5 100644
---- a/addons/lspclient/lspclientpluginview.cpp
-+++ b/addons/lspclient/lspclientpluginview.cpp
-@@ -990,11 +990,8 @@ public:
- if (!miface)
- return;
- auto mr = miface->newMovingRange(location);
-- static KTextEditor::Attribute::Ptr attr;
-- if (!attr) {
-- attr = new KTextEditor::Attribute;
-- attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
-- }
-+ KTextEditor::Attribute::Ptr attr(new KTextEditor::Attribute);
-+ attr->setUnderlineStyle(QTextCharFormat::SingleUnderline);
- mr->setView(view);
- mr->setAttribute(attr);
- QTimer::singleShot(1000, doc, [mr] {
---
-GitLab
-