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
84d27d3b
Commit
84d27d3b
authored
Sep 28, 2022
by
Christoph Cullmann
🍨
Browse files
ensure focus is inside editor widget on startup
avoid that session restore steals focus
parent
fd3ca02e
Pipeline
#238120
failed with stage
in 4 minutes and 38 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/lib/katemainwindow.cpp
View file @
84d27d3b
...
...
@@ -171,9 +171,8 @@ KateMainWindow::KateMainWindow(KConfig *sconfig, const QString &sgroup)
setSidebarsVisibleInternal
(
false
,
true
);
}
// in all cases: avoid that arbitrary plugin toolviews get focus, like terminal, bug 412227
// we need to delay this a bit due to lazy view creation (and lazy e.g. terminal widget creation)
QTimer
::
singleShot
(
0
,
m_viewManager
->
activeViewSpace
(),
SLOT
(
setFocus
()));
// trigger proper focus restore
m_viewManager
->
triggerActiveViewFocus
();
}
KateMainWindow
::~
KateMainWindow
()
...
...
apps/lib/katemainwindow.h
View file @
84d27d3b
...
...
@@ -136,6 +136,15 @@ public:
*/
void
saveOptions
();
/**
* Called if focus should go to the important part of the central widget.
*/
void
triggerFocusForCentralWidget
()
override
{
// just dispatch to view manager
m_viewManager
->
triggerActiveViewFocus
();
}
private:
/**
* Setup actions which pointers are needed already in setupMainWindow
...
...
apps/lib/katemdi.cpp
View file @
84d27d3b
...
...
@@ -887,7 +887,7 @@ void Sidebar::collapseSidebar()
}
// Now that tools are hidden, ensure the doc got the focus
m_mainWin
->
centralWidget
()
->
setFocus
();
m_mainWin
->
triggerFocusForCentralWidget
();
}
bool
Sidebar
::
adjustSplitterSections
()
...
...
@@ -1208,6 +1208,9 @@ void Sidebar::restoreSession(KConfigGroup &config)
auto
sz
=
config
.
readEntry
(
QStringLiteral
(
"Kate-MDI-Sidebar-%1-Splitter"
).
arg
(
position
()),
QList
<
int
>
());
QTimer
::
singleShot
(
100
,
this
,
[
this
,
sz
]()
{
setSizes
(
sz
);
// ensure focus is not stolen
m_mainWin
->
triggerFocusForCentralWidget
();
});
// ...now we are ready to get the final splitter sizes by MainWindow::finishRestore
updateSidebar
();
...
...
@@ -1472,7 +1475,7 @@ bool MainWindow::hideToolView(ToolView *widget)
}
const
bool
ret
=
widget
->
sidebar
()
->
hideToolView
(
widget
);
m_c
entralWidget
->
setFocus
();
triggerFocusForC
entralWidget
();
return
ret
;
}
...
...
@@ -1483,7 +1486,7 @@ void MainWindow::hideToolViews()
tv
->
sidebar
()
->
hideToolView
(
tv
);
}
}
m_c
entralWidget
->
setFocus
();
triggerFocusForC
entralWidget
();
}
void
MainWindow
::
startRestore
(
KConfigBase
*
config
,
const
QString
&
group
)
...
...
@@ -1546,6 +1549,9 @@ void MainWindow::finishRestore()
for
(
auto
&
sidebar
:
m_sidebars
)
{
sidebar
->
updateSidebar
();
}
// ensure focus is not stolen
triggerFocusForCentralWidget
();
});
}
...
...
apps/lib/katemdi.h
View file @
84d27d3b
...
...
@@ -498,11 +498,15 @@ public:
/**
* central widget ;)
* use this as parent for your content
* this widget will get focus if a toolview is hidden
* @return central widget
*/
QWidget
*
centralWidget
()
const
;
/**
* Called if focus should go to the important part of the central widget.
*/
virtual
void
triggerFocusForCentralWidget
()
=
0
;
protected:
/**
* Status bar area stacked widget.
...
...
apps/lib/kateviewmanager.cpp
View file @
84d27d3b
...
...
@@ -85,7 +85,9 @@ KateViewManager::KateViewManager(QWidget *parentW, KateMainWindow *parent)
if
(
activeViewSpace
()
&&
(
activeViewSpace
()
->
currentView
()
||
activeViewSpace
()
->
currentWidget
()))
return
;
// create new view & ensure focus
slotDocumentNew
();
triggerActiveViewFocus
();
});
}
else
{
// ensure we have the welcome view if no active view is there
...
...
@@ -1549,7 +1551,9 @@ void KateViewManager::showWelcomeViewIfNeeded()
if
(
activeViewSpace
()
&&
(
activeViewSpace
()
->
currentView
()
||
activeViewSpace
()
->
currentWidget
()))
return
;
// create welcome view & trigger focus of active view/widget
showWelcomeView
();
triggerActiveViewFocus
();
});
}
...
...
@@ -1587,3 +1591,24 @@ void KateViewManager::saveRecents()
{
mainWindow
()
->
recentFilesAction
()
->
saveEntries
(
KSharedConfig
::
openConfig
()
->
group
(
"Recent Files"
));
}
void
KateViewManager
::
triggerActiveViewFocus
()
{
// delay the focus, needed e.g. on startup
QTimer
::
singleShot
(
0
,
this
,
[
this
]()
{
// no active view space, bad!
if
(
!
activeViewSpace
())
{
return
;
}
// else: try to focus either the current active view or widget
if
(
auto
v
=
activeViewSpace
()
->
currentView
())
{
v
->
setFocus
();
return
;
}
if
(
auto
v
=
activeViewSpace
()
->
currentWidget
())
{
v
->
setFocus
();
return
;
}
});
}
apps/lib/kateviewmanager.h
View file @
84d27d3b
...
...
@@ -46,6 +46,11 @@ public:
KateViewManager
(
QWidget
*
parentW
,
KateMainWindow
*
parent
);
~
KateViewManager
()
override
;
/**
* triggered delayed focus set to current active view
*/
void
triggerActiveViewFocus
();
private:
/**
* create all actions needed for the view manager
...
...
Christoph Cullmann
🍨
@cullmann
mentioned in merge request
!908 (closed)
·
Sep 28, 2022
mentioned in merge request
!908 (closed)
mentioned in merge request !908
Toggle commit list
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