Keep Cupertino web search editable across clear and revisit
This commit is contained in:
@@ -82,9 +82,46 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _activeSearch {
|
||||
final scope = ShellBarScope.maybeOf(context);
|
||||
return scope == null ||
|
||||
scope.registry.focus == null ||
|
||||
scope.registry.focus == scope.destination;
|
||||
}
|
||||
|
||||
void _focusSearch() {
|
||||
final before = FocusManager.instance.primaryFocus;
|
||||
// The shell moves Search's field into its bar after changing tabs. End an
|
||||
// old browser edit only after that layout, then hand focus to the mounted
|
||||
// field. Ordinary query changes never reset focus or the input connection.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !_activeSearch || !_focus.canRequestFocus) return;
|
||||
final current = FocusManager.instance.primaryFocus;
|
||||
if (current != null &&
|
||||
current != before &&
|
||||
current != _focus &&
|
||||
current is! FocusScopeNode) {
|
||||
return;
|
||||
}
|
||||
_focus.unfocus();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !_activeSearch || !_focus.canRequestFocus) return;
|
||||
final current = FocusManager.instance.primaryFocus;
|
||||
if (current == null ||
|
||||
current == _focus ||
|
||||
current == before ||
|
||||
current is FocusScopeNode) {
|
||||
_focus.requestFocus();
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
ShellSearchShortcut(onFocus: _focus.requestFocus, child: _build(context));
|
||||
ShellSearchShortcut(onFocus: _focusSearch, child: _build(context));
|
||||
|
||||
Widget _build(BuildContext context) {
|
||||
// Follow the actual host app class: Cupertino only under an explicit
|
||||
|
||||
Reference in New Issue
Block a user