Skip to content

Commit 2b98174

Browse files
committed
Expose the key of the InputListener to externally so that the caller can give the terminal focus, not just get focus by tap
1 parent 888d036 commit 2b98174

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

lib/frontend/input_listener.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ abstract class InputListenerController {
1515

1616
class InputListener extends StatefulWidget {
1717
InputListener({
18+
Key? key,
1819
required this.child,
1920
required this.onKeyStroke,
2021
required this.onTextInput,
@@ -30,7 +31,7 @@ class InputListener extends StatefulWidget {
3031
this.inputAction = TextInputAction.done,
3132
this.keyboardAppearance = Brightness.light,
3233
this.autocorrect = false,
33-
});
34+
}):super(key:key);
3435

3536
final Widget child;
3637
final InputHandler onTextInput;

lib/frontend/terminal_view.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class _TerminalViewState extends State<TerminalView> {
169169
@override
170170
Widget build(BuildContext context) {
171171
return InputListener(
172+
key: widget.terminal.inputKey,
172173
listenKeyStroke: widget.inputBehavior.acceptKeyStroke,
173174
onKeyStroke: onKeyStroke,
174175
onTextInput: onInput,

lib/terminal/terminal.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import 'dart:async';
22
import 'dart:collection';
33
import 'dart:math' show max, min;
44

5+
import 'package:flutter/src/widgets/framework.dart';
56
import 'package:xterm/buffer/buffer.dart';
67
import 'package:xterm/buffer/line/line.dart';
8+
import 'package:xterm/frontend/input_listener.dart';
79
import 'package:xterm/input/keys.dart';
810
import 'package:xterm/input/keytab/keytab.dart';
911
import 'package:xterm/input/keytab/keytab_escape.dart';
@@ -40,6 +42,7 @@ class Terminal
4042
with Observable
4143
implements TerminalUiInteraction, TerminalSearchInteraction {
4244
Terminal({
45+
this.inputKey,
4346
this.backend,
4447
this.onBell = _defaultBellHandler,
4548
this.onTitleChange = _defaultTitleHandler,
@@ -805,4 +808,7 @@ class Terminal
805808
setScrollOffsetFromBottom(buffer.height - desiredScrollOffsetFromTop);
806809
}
807810
}
811+
812+
@override
813+
GlobalKey<InputListenerState>? inputKey;
808814
}

lib/terminal/terminal_ui_interaction.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:flutter/cupertino.dart';
12
import 'package:xterm/buffer/line/line.dart';
3+
import 'package:xterm/frontend/input_listener.dart';
24
import 'package:xterm/input/keys.dart';
35
import 'package:xterm/mouse/position.dart';
46
import 'package:xterm/mouse/selection.dart';
@@ -12,6 +14,8 @@ abstract class TerminalUiInteraction with Observable {
1214
/// The theme associated with this Terminal
1315
TerminalTheme get theme;
1416

17+
GlobalKey<InputListenerState>? inputKey;
18+
1519
/// the ViewPort scroll offset from the bottom
1620
int get scrollOffsetFromBottom;
1721

0 commit comments

Comments
 (0)