Commit acf27561 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

improve view reusing

only re-use if never modified and the url we try to open
is not already opened
parent cd02fdfc
Pipeline #136967 passed with stage
in 3 minutes and 49 seconds
......@@ -576,6 +576,13 @@ void KateDocManager::slotModChanged1(KTextEditor::Document *doc)
// clang-format off
QMetaObject::invokeMethod(KateApp::self()->activeKateMainWindow(), "queueModifiedOnDisc", Qt::QueuedConnection, Q_ARG(KTextEditor::Document*,doc));
// clang-format on
if (doc->isModified()) {
KateDocumentInfo *info = documentInfo(doc);
if (info) {
info->wasDocumentEverModified = true;
}
}
}
void KateDocManager::documentOpened()
......
......@@ -35,6 +35,7 @@ public:
bool openedByUser = false;
bool openSuccess = true;
bool doPostLoadOperations = false;
bool wasDocumentEverModified = false;
};
class KateDocManager : public QObject
......
......@@ -125,11 +125,19 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
// like other editors, we try to re-use documents, of not modified
connect(m_urlBar, &KateUrlBar::openUrlRequested, this, [this](const QUrl &url) {
if (auto activeView = m_viewManager->activeView(); activeView && !activeView->document()->isModified()) {
activeView->document()->openUrl(url);
} else {
m_viewManager->openUrl(url);
// try if reuse of view make sense
if (!KateApp::self()->documentManager()->findDocument(url)) {
if (auto activeView = m_viewManager->activeView(); activeView) {
KateDocumentInfo *info = KateApp::self()->documentManager()->documentInfo(activeView->document());
if (info && !info->wasDocumentEverModified) {
activeView->document()->openUrl(url);
return;
}
}
}
// default: open a new document or switch there
m_viewManager->openUrl(url);
});
layout->addWidget(m_urlBar);
......
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