Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
7014499f
Commit
7014499f
authored
Oct 22, 2022
by
Waqar Ahmed
Committed by
Christoph Cullmann
Oct 22, 2022
Browse files
Fix doc closing when active doc is in multiple viewspaces
BUG: 460613
parent
7935d433
Pipeline
#253541
canceled with stage
in 11 minutes and 5 seconds
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
apps/lib/autotests/kate_view_mgmt_tests.cpp
View file @
7014499f
...
...
@@ -8,6 +8,8 @@
#include
"kateviewspace.h"
#include
"ktexteditor_utils.h"
#include
<KTextEditor/Editor>
#include
<QCommandLineParser>
#include
<QPointer>
#include
<QSignalSpy>
...
...
@@ -319,3 +321,42 @@ void KateViewManagementTests::testActivateNotAddedWidget()
QVERIFY
(
spy
.
count
()
==
1
);
QVERIFY
(
spy1
.
count
()
==
1
);
}
void
KateViewManagementTests
::
testBug460613
()
{
// See the bug for details
// This test basically splits into two viewspaces
// Both viewspaces have 1 view
// Adds a new doc to first viewsace and activates
// and then adds the same doc to second viewspace
// without activation
// TEST: closing the doc should only close it
// in the first viewspace, not second as well!
// TEST: closing the doc without view should work
app
->
sessionManager
()
->
activateAnonymousSession
();
KateMainWindow
*
mw
=
app
->
activeKateMainWindow
();
auto
vm
=
mw
->
viewManager
();
vm
->
createView
(
nullptr
);
vm
->
slotSplitViewSpaceVert
();
QCOMPARE
(
vm
->
m_viewSpaceList
.
size
(),
2
);
auto
vs1
=
*
vm
->
m_viewSpaceList
.
begin
();
auto
vs2
=
*
(
vm
->
m_viewSpaceList
.
begin
()
+
1
);
vs1
->
createNewDocument
();
QCOMPARE
(
vm
->
activeView
(),
vs1
->
currentView
());
KTextEditor
::
Document
*
doc
=
vm
->
activeView
()
->
document
();
vs2
->
registerDocument
(
doc
);
// registered, but has no view yet
vm
->
slotDocumentClose
();
// The doc should still be there in the second viewspace
QVERIFY
(
vs2
->
m_registeredDocuments
.
contains
(
doc
));
// Try to close the doc in second viewspace
vs2
->
closeDocument
(
doc
);
QVERIFY
(
!
vs2
->
hasDocument
(
doc
));
}
apps/lib/autotests/kate_view_mgmt_tests.h
View file @
7014499f
...
...
@@ -35,6 +35,7 @@ private Q_SLOTS:
void
testWidgetAddedEmittedOnAddWidget
();
void
testWidgetRemovedEmittedOnRemoveWidget
();
void
testActivateNotAddedWidget
();
void
testBug460613
();
private:
class
QTemporaryDir
*
m_tempdir
;
...
...
apps/lib/kateviewmanager.cpp
View file @
7014499f
...
...
@@ -1163,6 +1163,31 @@ void KateViewManager::onViewSpaceEmptied(KateViewSpace *vs)
showWelcomeViewOrNewDocumentIfNeeded
();
}
int
KateViewManager
::
viewspaceCountForDoc
(
KTextEditor
::
Document
*
doc
)
const
{
return
std
::
count_if
(
m_viewSpaceList
.
begin
(),
m_viewSpaceList
.
end
(),
[
doc
](
KateViewSpace
*
vs
)
{
return
vs
->
hasDocument
(
doc
);
});
}
bool
KateViewManager
::
docOnlyInOneViewspace
(
KTextEditor
::
Document
*
doc
)
const
{
auto
count
=
viewspaceCountForDoc
(
doc
);
if
(
count
>
1
)
{
return
false
;
}
std
::
vector
<
KateMainWindow
*>
mainWindows
;
const
auto
mws
=
KateApp
::
self
()
->
mainWindows
();
for
(
auto
*
mw
:
mws
)
{
auto
w
=
qobject_cast
<
KateMainWindow
*>
(
mw
->
window
());
if
(
w
&&
w
!=
m_mainWindow
)
{
count
+=
w
->
viewManager
()
->
viewspaceCountForDoc
(
doc
);
}
}
return
count
==
1
;
}
void
KateViewManager
::
setShowUrlNavBar
(
bool
show
)
{
if
(
show
!=
m_showUrlNavBar
)
{
...
...
apps/lib/kateviewmanager.h
View file @
7014499f
...
...
@@ -311,6 +311,11 @@ public Q_SLOTS:
void
onViewSpaceEmptied
(
KateViewSpace
*
vs
);
// Returns the number of viewspaces this document is registered in
int
viewspaceCountForDoc
(
KTextEditor
::
Document
*
doc
)
const
;
// returns true if @p doc exists only in one viewspace
bool
docOnlyInOneViewspace
(
KTextEditor
::
Document
*
doc
)
const
;
void
setShowUrlNavBar
(
bool
show
);
bool
showUrlNavBar
()
const
;
...
...
apps/lib/kateviewspace.cpp
View file @
7014499f
...
...
@@ -543,7 +543,7 @@ void KateViewSpace::closeDocument(KTextEditor::Document *doc)
// OR the doc has no views yet
// just close the document and it will take
// care of removing the view + cleaning up the doc
if
(
doc
->
views
().
size
()
<=
1
)
{
if
(
m_viewManager
->
docOnlyInOneViewspace
(
doc
)
)
{
m_viewManager
->
slotDocumentClose
(
doc
);
}
else
{
// KTE::view for this tab has been created yet?
...
...
@@ -622,7 +622,7 @@ void KateViewSpace::dropEvent(QDropEvent *e)
bool
KateViewSpace
::
hasDocument
(
KTextEditor
::
Document
*
doc
)
const
{
return
m_registeredDocuments
.
contains
(
doc
)
&&
(
m_docToView
.
find
(
doc
)
!=
m_docToView
.
end
())
;
return
m_registeredDocuments
.
contains
(
doc
);
}
KTextEditor
::
View
*
KateViewSpace
::
takeView
(
KTextEditor
::
Document
*
doc
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment