Commit 9880babc authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Improve views closing in split view behaviour

Currently if you have a doc that has 2 views in 2 different splits:

A | A

and you close one of them, it closes the other as well. This behaviour
is really non-intuitive and is very unexpected to say the least. To
start with, no one asked kate to close the other view so it shouldn't
auto close it.

Moreover suppose you have a viewspace with:

AB

and you want to open a new split, the new split will open to the *left*
of the current one resulting in: A | AB, instead of AB | A. This is
the opposite of what any app does.

With this change, I am proposing a different solution:
- If a doc has multiple views, only close the one that the user asked
  for in the current viewspace.
- If the viewspace becomes empty, there is no need to refill it, close
  the viewspace. If this is the last viewspace, it remains open.
- Lastly, when doing vertical split, open the new viewspace *after* the
  current one not before.

This behaviour is consistent with other editors and apps doing splits.

BUG: 344374
parent 8c125d2a
Pipeline #124937 passed with stage
in 4 minutes and 23 seconds
......@@ -275,14 +275,15 @@ void KateViewManager::slotDocumentClose()
return;
}
if (auto vs = activeViewSpace()) {
auto vs = activeViewSpace();
if (vs) {
if (auto w = vs->currentWidget()) {
vs->closeTabWithWidget(w);
return;
}
}
slotDocumentClose(view->document());
vs->closeDocument(view->document());
}
}
KTextEditor::Document *KateViewManager::openUrl(const QUrl &url, const QString &encoding, bool activate, bool isTempFile, const KateDocumentInfo &docInfo)
......@@ -818,7 +819,7 @@ void KateViewManager::splitViewSpace(KateViewSpace *vs, // = 0
QList<int> sizes = currentSplitter->sizes();
sizes << (sizes.first() - currentSplitter->handleWidth()) / 2;
sizes[0] = sizes[1];
currentSplitter->insertWidget(index, vsNew);
currentSplitter->insertWidget(index + 1, vsNew);
currentSplitter->setSizes(sizes);
} else {
// create a new KateSplitter and replace vs with the splitter. vs and newVS are
......@@ -889,6 +890,15 @@ void KateViewManager::toggleSplitterOrientation()
}
}
void KateViewManager::onViewSpaceEmptied(KateViewSpace *vs)
{
// If we have more than one viewspaces and this viewspace
// got empty, remove it
if (m_viewSpaceList.size() > 1) {
removeViewSpace(vs);
}
}
bool KateViewManager::viewsInSameViewSpace(KTextEditor::View *view1, KTextEditor::View *view2)
{
if (!view1 || !view2) {
......
......@@ -106,9 +106,9 @@ public:
*/
KTextEditor::View *createView(KTextEditor::Document *doc = nullptr, KateViewSpace *vs = nullptr);
private:
bool deleteView(KTextEditor::View *view);
private:
void moveViewtoSplit(KTextEditor::View *view);
void moveViewtoStack(KTextEditor::View *view);
......@@ -284,6 +284,8 @@ public Q_SLOTS:
return ret;
}
void onViewSpaceEmptied(KateViewSpace *vs);
private:
KateMainWindow *m_mainWindow;
bool m_init;
......
......@@ -127,6 +127,8 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
connect(m_viewManager->mainWindow(), &KateMainWindow::statusBarToggled, this, &KateViewSpace::statusBarToggled);
connect(m_viewManager->mainWindow(), &KateMainWindow::tabBarToggled, this, &KateViewSpace::tabBarToggled);
connect(this, &KateViewSpace::viewSpaceEmptied, m_viewManager, &KateViewManager::onViewSpaceEmptied);
// init the bars...
statusBarToggled();
tabBarToggled();
......@@ -395,6 +397,32 @@ void KateViewSpace::registerDocument(KTextEditor::Document *doc)
connect(m_tabBar, &KateTabBar::currentChanged, this, &KateViewSpace::changeView);
}
void KateViewSpace::closeDocument(KTextEditor::Document *doc)
{
auto it = m_docToView.find(doc);
Q_ASSERT(it != m_docToView.end());
// If this is the only view of the document,
// just close the document and it will take
// care of removing the view + cleaning up the doc
if (doc->views().size() == 1) {
m_viewManager->slotDocumentClose(doc);
} else {
// We have other views of this doc in other viewspaces
// Just remove the view
m_viewManager->deleteView(it->second);
// Clean up this doc from this viewspace
documentDestroyed(doc);
}
/**
* if this was the last doc, let viewManager know we are empty
*/
if (m_registeredDocuments.isEmpty() && m_tabBar->count() == 0) {
Q_EMIT viewSpaceEmptied(this);
}
}
void KateViewSpace::documentDestroyed(QObject *doc)
{
/**
......@@ -473,7 +501,7 @@ void KateViewSpace::closeTabRequest(int idx)
return;
}
m_viewManager->slotDocumentClose(doc);
closeDocument(doc);
}
void KateViewSpace::createNewDocument()
......
......@@ -77,6 +77,11 @@ public:
*/
void registerDocument(KTextEditor::Document *doc);
/**
* closes the view of the provided doc in this viewspace
*/
void closeDocument(KTextEditor::Document *doc);
/**
* Event filter to catch events from view space tool buttons.
*/
......@@ -141,6 +146,8 @@ public:
void addPositionToHistory(const QUrl &url, KTextEditor::Cursor, bool calledExternally = false);
// END Location History Stuff
Q_SIGNALS:
void viewSpaceEmptied(KateViewSpace *vs);
public Q_SLOTS:
void documentDestroyed(QObject *doc);
......
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