Commit 3cb05466 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Use KTextEditor::Cursor and connect pluginView only

parent 87ed61bd
......@@ -64,13 +64,6 @@ public:
return m_configPath.isEmpty() ? m_defaultConfigPath : m_configPath;
}
Q_SIGNALS:
/**
* Signal that we jumped to a location
*/
void jumped(const QUrl &, int line, int col);
private:
Q_SIGNALS:
// signal settings update
......
......@@ -412,7 +412,7 @@ Q_SIGNALS:
/**
* Signal that we jumped to a location
*/
void jumped(const QUrl &url, int line, int col);
void jumped(const QUrl &url, KTextEditor::Cursor c);
public:
LSPClientActionView(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin, KXMLGUIClient *client, QSharedPointer<LSPClientServerManager> serverManager)
......@@ -664,7 +664,6 @@ public:
if (mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::ControlModifier) {
// must set cursor else we will be jumping somewhere else!!
v->setCursorPosition(cur);
Q_EMIT jumped(v->document()->url(), cur.line(), cur.column());
if (!word.isEmpty()) {
m_ctrlHoverFeedback.clear(m_mainWindow->activeView());
goToDefinition();
......@@ -1031,8 +1030,13 @@ public:
KTextEditor::Document *document = activeView->document();
KTextEditor::Cursor cdef(line, column);
// tell Kate we have jumped to this location for record
Q_EMIT jumped(uri, line, column);
// tell Kate we are jumping "from" this location
if (document) {
Q_EMIT jumped(document->url(), activeView->cursorPosition());
}
// tell Kate we are jumping "to" this location
Q_EMIT jumped(uri, cdef);
if (document && uri == document->url()) {
activeView->setCursorPosition(cdef);
......@@ -2425,7 +2429,6 @@ public:
connect(m_actionView.get(), &LSPClientActionView::message, this, &LSPClientPluginViewImpl::message);
connect(m_actionView.get(), &LSPClientActionView::jumped, this, &LSPClientPluginViewImpl::jumped);
connect(this, &self_type::jumped, plugin, &LSPClientPlugin::jumped);
}
~LSPClientPluginViewImpl() override
......@@ -2450,7 +2453,7 @@ Q_SIGNALS:
/**
* Signal that we jumped to a location
*/
void jumped(const QUrl &url, int line, int col);
void jumped(const QUrl &url, KTextEditor::Cursor c);
};
QObject *LSPClientPluginView::new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin)
......
......@@ -1181,9 +1181,9 @@ QObject *KateMainWindow::pluginView(const QString &name)
return m_pluginViews.contains(plugin) ? m_pluginViews.value(plugin) : nullptr;
}
void KateMainWindow::addJumpLocation(QUrl url, int line, int col)
void KateMainWindow::addJump(QUrl url, KTextEditor::Cursor c)
{
m_locations.push_back({url, line, col});
m_locations.push_back({url, c});
// set to last
currentLocation = m_locations.size() - 1;
}
......@@ -1257,17 +1257,20 @@ void KateMainWindow::goBack()
auto location = m_locations.at(currentLocation - 1);
currentLocation--;
if (!location.url.isValid()) {
if (!location.url.isValid() || !location.cursor.isValid()) {
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), QStringLiteral("Error"));
genericMessage.insert(QStringLiteral("category"), i18n("Git"));
genericMessage.insert(QStringLiteral("text"), i18n("Failed to jump to: %1 %2 %3", location.url.toDisplayString(), location.line, location.col));
genericMessage.insert(QStringLiteral("text"),
i18n("Failed to jump to: %1 %2 %3", location.url.toDisplayString(), location.cursor.line(), location.cursor.column()));
m_outputView->slotMessage(genericMessage);
m_locations.remove(currentLocation);
return;
}
auto v = openUrl(location.url);
v->setCursorPosition({location.line, location.col});
v->setCursorPosition(location.cursor);
}
void KateMainWindow::goForward()
......@@ -1280,19 +1283,22 @@ void KateMainWindow::goForward()
}
auto location = m_locations.at(currentLocation + 1);
currentLocation--;
currentLocation++;
if (!location.url.isValid()) {
if (!location.url.isValid() || !location.cursor.isValid()) {
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), QStringLiteral("Error"));
genericMessage.insert(QStringLiteral("category"), i18n("Git"));
genericMessage.insert(QStringLiteral("text"), i18n("Failed to jump to: %1 %2 %3", location.url.toDisplayString(), location.line, location.col));
genericMessage.insert(QStringLiteral("text"),
i18n("Failed to jump to: %1 %2 %3", location.url.toDisplayString(), location.cursor.line(), location.cursor.column()));
m_outputView->slotMessage(genericMessage);
m_locations.remove(currentLocation);
return;
}
auto v = openUrl(location.url);
v->setCursorPosition({location.line, location.col});
v->setCursorPosition(location.cursor);
}
QWidget *KateMainWindow::createToolView(KTextEditor::Plugin *plugin,
......
......@@ -522,7 +522,7 @@ public Q_SLOTS:
/**
* Add a jump location for jumping back and forth between history
*/
void addJumpLocation(QUrl url, int line, int col);
void addJump(QUrl url, KTextEditor::Cursor);
private Q_SLOTS:
void slotUpdateBottomViewBar();
......@@ -580,8 +580,7 @@ private:
struct Location {
QUrl url;
int line;
int col;
KTextEditor::Cursor cursor;
};
QVector<Location> m_locations;
......
......@@ -229,11 +229,6 @@ void KatePluginManager::enablePluginGUI(KatePluginInfo *item, KateMainWindow *wi
connect(item->plugin, SIGNAL(message(const QVariantMap &)), win->outputView(), SLOT(slotMessage(const QVariantMap &)), Qt::UniqueConnection);
}
// ensure jumping is connected for plugin if available
if (item->plugin->metaObject()->indexOfSignal("jumped(QUrl,int,int)") != -1) {
connect(item->plugin, SIGNAL(jumped(const QUrl &, int, int)), win, SLOT(addJumpLocation(const QUrl &, int, int)), Qt::UniqueConnection);
}
// create the view + try to correctly load shortcuts, if it's a GUI Client
createdView = item->plugin->createView(win->wrapper());
if (createdView) {
......@@ -243,6 +238,15 @@ void KatePluginManager::enablePluginGUI(KatePluginInfo *item, KateMainWindow *wi
if (createdView->metaObject()->indexOfSignal("message(QVariantMap)") != -1) {
connect(createdView, SIGNAL(message(const QVariantMap &)), win->outputView(), SLOT(slotMessage(const QVariantMap &)), Qt::UniqueConnection);
}
// ensure jumping is connected for plugin view if available
if (createdView->metaObject()->indexOfSignal("jumped(QUrl,KTextEditor::Cursor)") != -1) {
connect(createdView,
SIGNAL(jumped(const QUrl &, KTextEditor::Cursor)),
win,
SLOT(addJump(const QUrl &, KTextEditor::Cursor)),
Qt::UniqueConnection);
}
}
}
......
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