Commit 26c6b306 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Reintroduce position signal for location saving


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent cfa8116f
......@@ -238,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 location tracking is connected for view
if (createdView->metaObject()->indexOfSignal("posChanged(QUrl,KTextEditor::Cursor)") != -1) {
connect(createdView,
SIGNAL(posChanged(QUrl, KTextEditor::Cursor)),
win->viewManager(),
SLOT(savePosition(const QUrl &, KTextEditor::Cursor)),
Qt::UniqueConnection);
}
}
}
......
......@@ -322,6 +322,13 @@ void KateViewManager::openUrl(const QUrl &url)
openUrl(url, QString());
}
void KateViewManager::savePosition(const QUrl &url, KTextEditor::Cursor pos)
{
if (KateViewSpace *avs = activeViewSpace()) {
avs->addJump(url, pos, /* calledExternally: */ true);
}
}
KateMainWindow *KateViewManager::mainWindow()
{
return m_mainWindow;
......
......@@ -67,6 +67,7 @@ public:
public Q_SLOTS:
void openUrl(const QUrl &url);
void savePosition(const QUrl &url, KTextEditor::Cursor pos);
public:
void closeView(KTextEditor::View *view);
......
......@@ -474,8 +474,13 @@ void KateViewSpace::focusNextTab()
}
}
void KateViewSpace::addJump(const QUrl &url, KTextEditor::Cursor c)
void KateViewSpace::addJump(const QUrl &url, KTextEditor::Cursor c, bool calledExternally)
{
// We don't care about invalid urls (Fixed Diff View / Untitled docs)
if (!url.isValid()) {
return;
}
// we are in the middle of jumps somewhere?
if (!m_locations.isEmpty() && currentLocation + 1 < m_locations.size()) {
// erase all forward history
......@@ -487,15 +492,30 @@ void KateViewSpace::addJump(const QUrl &url, KTextEditor::Cursor c)
m_locations.pop_back();
}
// limit size to 100, remove first 20
if (m_locations.size() >= 100) {
m_locations.erase(m_locations.begin(), m_locations.begin() + 20);
// Check if the location is at least "viewLineCount" away
if (!calledExternally && !m_locations.isEmpty() && m_locations.back().url == url) {
int line = c.line();
int lastLocLine = m_locations.back().cursor.line();
auto view = m_viewManager->activeView();
int viewLineCount = view->lastDisplayedLine() - view->firstDisplayedLine();
int lowerBound = lastLocLine - viewLineCount;
int upperBound = lastLocLine + viewLineCount;
if (lowerBound <= line && line <= upperBound) {
return;
}
}
// limit size to 50, remove first 10
if (m_locations.size() >= 50) {
m_locations.erase(m_locations.begin(), m_locations.begin() + 10);
}
// this is our new forward
/** this is our new forward **/
m_locations.push_back({url, c});
// set to last
// set currentLocation as last
currentLocation = m_locations.size() - 1;
// disable forward button as we are at the end now
m_historyForward->setEnabled(false);
......
......@@ -91,6 +91,8 @@ public:
*/
void focusNextTab();
/** BEGIN Location History Stuff **/
/**
* go forward in location history
*/
......@@ -111,6 +113,13 @@ public:
*/
bool isHistoryForwardEnabled() const;
/**
* Add a jump location for jumping back and forth between history
*/
void addJump(const QUrl &url, KTextEditor::Cursor, bool calledExternally = false);
/** END Location History Stuff **/
public Q_SLOTS:
void documentDestroyed(QObject *doc);
void updateDocumentName(KTextEditor::Document *doc);
......@@ -156,11 +165,6 @@ private:
*/
int hiddenDocuments() const;
/**
* Add a jump location for jumping back and forth between history
*/
void addJump(const QUrl &url, KTextEditor::Cursor);
private:
// Kate's view manager
KateViewManager *m_viewManager;
......
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