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
098f435f
Commit
098f435f
authored
Sep 30, 2022
by
Waqar Ahmed
Committed by
Christoph Cullmann
Oct 01, 2022
Browse files
Fix lru tab switching when there are widgets
parent
34bb6dca
Changes
2
Hide whitespace changes
Inline
Side-by-side
apps/lib/kateviewspace.cpp
View file @
098f435f
...
...
@@ -369,9 +369,12 @@ void KateViewSpace::removeView(KTextEditor::View *v)
// (last element could well be v->document() being removed here)
bool
shown
=
false
;
for
(
auto
rit
=
m_registeredDocuments
.
rbegin
();
rit
!=
m_registeredDocuments
.
rend
();
++
rit
)
{
auto
it
=
m_docToView
.
find
(
*
rit
);
if
(
it
!=
m_docToView
.
end
())
{
shown
=
showView
(
*
rit
);
if
(
auto
doc
=
rit
->
doc
())
{
shown
=
showView
(
doc
);
break
;
}
else
if
(
auto
wid
=
rit
->
widget
())
{
activateWidget
(
wid
);
shown
=
true
;
break
;
}
}
...
...
@@ -742,10 +745,26 @@ void KateViewSpace::closeTabRequest(int idx)
QMetaObject
::
invokeMethod
(
widget
,
"shouldClose"
,
Q_RETURN_ARG
(
bool
,
shouldClose
));
if
(
shouldClose
)
{
stack
->
removeWidget
(
widget
);
m_registeredDocuments
.
removeOne
(
widget
);
m_tabBar
->
blockSignals
(
true
);
m_tabBar
->
removeTab
(
idx
);
m_tabBar
->
blockSignals
(
false
);
widget
->
deleteLater
();
Q_EMIT
m_viewManager
->
mainWindow
()
->
widgetRemoved
(
widget
);
// switch to most recently used doc
for
(
auto
rit
=
m_registeredDocuments
.
rbegin
();
rit
!=
m_registeredDocuments
.
rend
();
++
rit
)
{
if
(
auto
doc
=
rit
->
doc
())
{
showView
(
doc
);
break
;
}
else
if
(
auto
wid
=
rit
->
widget
())
{
activateWidget
(
wid
);
break
;
}
}
// if this was the last doc, let viewManager know we are empty
if
(
m_registeredDocuments
.
isEmpty
()
&&
m_tabBar
->
count
()
==
0
)
{
Q_EMIT
viewSpaceEmptied
(
this
);
...
...
@@ -792,6 +811,7 @@ void KateViewSpace::addWidgetAsTab(QWidget *widget)
stack
->
addWidget
(
widget
);
m_tabBar
->
setCurrentWidget
(
widget
);
stack
->
setCurrentWidget
(
widget
);
m_registeredDocuments
.
append
(
widget
);
}
bool
KateViewSpace
::
hasWidgets
()
const
...
...
@@ -844,6 +864,9 @@ bool KateViewSpace::activateWidget(QWidget *widget)
for
(
int
i
=
0
;
i
<
m_tabBar
->
count
();
++
i
)
{
if
(
m_tabBar
->
tabData
(
i
).
value
<
QWidget
*>
()
==
widget
)
{
m_tabBar
->
setCurrentIndex
(
i
);
m_registeredDocuments
.
removeOne
(
widget
);
m_registeredDocuments
.
append
(
widget
);
return
true
;
}
}
...
...
apps/lib/kateviewspace.h
View file @
098f435f
...
...
@@ -298,13 +298,35 @@ private:
std
::
vector
<
Location
>
m_locations
;
size_t
currentLocation
=
0
;
struct
DocOrWidget
:
public
std
::
variant
<
KTextEditor
::
Document
*
,
QWidget
*>
{
using
variant
::
variant
;
auto
*
doc
()
const
{
return
std
::
holds_alternative
<
KTextEditor
::
Document
*>
(
*
this
)
?
std
::
get
<
KTextEditor
::
Document
*>
(
*
this
)
:
nullptr
;
}
auto
widget
()
const
{
return
std
::
holds_alternative
<
QWidget
*>
(
*
this
)
?
std
::
get
<
QWidget
*>
(
*
this
)
:
nullptr
;
}
bool
operator
==
(
KTextEditor
::
Document
*
doc
)
const
{
return
this
->
doc
()
==
doc
;
}
bool
operator
==
(
QWidget
*
w
)
const
{
return
this
->
widget
()
==
w
;
}
};
/**
* all documents this view space is aware of
* depending on the limit of tabs, not all will have a corresponding
* tab in the KateTabBar
* these are stored in used order (MRU last)
*/
QVector
<
KTextEditor
::
Document
*
>
m_registeredDocuments
;
QVector
<
DocOrWidget
>
m_registeredDocuments
;
// the list of views that are contained in this view space,
// mapped through a hash from Document to View.
...
...
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