Commit d5354b0a authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: use managed cleanup and unordered_map in hover document tracking

parent 152acb67
......@@ -49,6 +49,7 @@
#include <QTextCodec>
#include <QTimer>
#include <QTreeView>
#include <unordered_map>
#include <utility>
namespace RangeData
......@@ -221,7 +222,7 @@ public:
}
// underline the hovered word
auto mr = data.range;
auto &mr = data.range;
if (mr) {
mr->setRange(range);
} else {
......@@ -229,8 +230,7 @@ public:
if (!miface) {
return;
}
mr = miface->newMovingRange(range);
data.range = mr;
mr.reset(miface->newMovingRange(range));
// clang-format off
connect(doc,
SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document*)),
......@@ -259,7 +259,7 @@ public:
auto doc = activeView->document();
auto it = docs.find(doc);
if (it != docs.end()) {
auto &data = *it;
auto &data = it->second;
auto &mr = data.range;
if (mr) {
mr->setRange(KTextEditor::Range::invalid());
......@@ -290,9 +290,9 @@ private:
if (doc) {
auto it = docs.find(doc);
if (it != docs.end()) {
delete it->range;
if (it->wid) {
it->wid->setCursor(it->cursor);
auto &data = it->second;
if (data.wid) {
data.wid->setCursor(data.cursor);
}
docs.erase(it);
}
......@@ -301,14 +301,14 @@ private:
private:
struct DocumentData {
KTextEditor::MovingRange *range = nullptr;
std::unique_ptr<KTextEditor::MovingRange> range = nullptr;
// widget to restore cursor on
QPointer<QWidget> wid;
QCursor cursor;
};
QPointer<QWidget> w;
QHash<KTextEditor::Document *, DocumentData> docs;
std::unordered_map<KTextEditor::Document *, DocumentData> docs;
KTextEditor::Range range;
};
......
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