diff --git a/lib/view/page/ssh/page.dart b/lib/view/page/ssh/page.dart index 21d9afbd..7701f135 100644 --- a/lib/view/page/ssh/page.dart +++ b/lib/view/page/ssh/page.dart @@ -5,6 +5,7 @@ import 'package:dartssh2/dartssh2.dart'; import 'package:fl_lib/fl_lib.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:provider/provider.dart'; import 'package:toolbox/core/extension/context/locale.dart'; @@ -30,6 +31,7 @@ class SSHPage extends StatefulWidget { final String? initCmd; final bool notFromTab; final Function()? onSessionEnd; + final FocusNode? focus; const SSHPage({ super.key, @@ -37,6 +39,7 @@ class SSHPage extends StatefulWidget { this.initCmd, this.notFromTab = true, this.onSessionEnd, + this.focus, }); @override @@ -50,7 +53,7 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { late final _terminal = Terminal(inputHandler: _keyboard); final TerminalController _terminalController = TerminalController(); final List> _virtKeysList = []; - final _focus = FocusNode(); + late final _focus = widget.focus ?? FocusNode(); late MediaQueryData _media; late TerminalStyle _terminalStyle; diff --git a/lib/view/page/ssh/tab.dart b/lib/view/page/ssh/tab.dart index 17960119..1f7cfd3b 100644 --- a/lib/view/page/ssh/tab.dart +++ b/lib/view/page/ssh/tab.dart @@ -25,6 +25,7 @@ class _SSHTabPageState extends State vsync: this, ); final _fabRN = ValueNotifier(0); + final _focusMap = {}; @override Widget build(BuildContext context) { @@ -36,7 +37,10 @@ class _SSHTabPageState extends State isScrollable: true, tabAlignment: TabAlignment.start, dividerColor: Colors.transparent, - onTap: (value) => _fabRN.value = value, + onTap: (value) { + _fabRN.value = value; + _focusMap[_tabIds.keys.elementAt(value)]?.requestFocus(); + }, ), body: _buildBody(), floatingActionButton: ListenableBuilder( @@ -138,10 +142,10 @@ class _SSHTabPageState extends State } return spi.name; }(); - final key = GlobalKey>(debugLabel: 'sshTabPage_$name'); + final focus = _focusMap.putIfAbsent(name, () => FocusNode()); _tabIds[name] = SSHPage( - key: key, spi: spi, + focus: focus, notFromTab: false, onSessionEnd: () { // debugPrint("Session done received on page whose tabId = $name");