Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/src/terminal_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TerminalView extends StatefulWidget {
this.readOnly = false,
this.hardwareKeyboardOnly = false,
this.simulateScroll = true,
this.scrollOnInput = true,
});

/// The underlying terminal that this widget renders.
Expand Down Expand Up @@ -141,6 +142,11 @@ class TerminalView extends StatefulWidget {
/// emulators. True by default.
final bool simulateScroll;

/// If true, the terminal will automatically scroll to the bottom when the
/// user provides input. Set to false to handle scroll positioning externally.
/// True by default.
final bool scrollOnInput;

@override
State<TerminalView> createState() => TerminalViewState();
}
Expand Down Expand Up @@ -257,12 +263,12 @@ class TerminalViewState extends State<TerminalView> {
deleteDetection: widget.deleteDetection,
onInsert: _onInsert,
onDelete: () {
_scrollToBottom();
if (widget.scrollOnInput) _scrollToBottom();
widget.terminal.keyInput(TerminalKey.backspace);
},
onComposing: _onComposing,
onAction: (action) {
_scrollToBottom();
if (widget.scrollOnInput) _scrollToBottom();
// Android sends TextInputAction.newline when the user presses the virtual keyboard's enter key.
if (action == TextInputAction.done || action == TextInputAction.newline) {
widget.terminal.keyInput(TerminalKey.enter);
Expand Down Expand Up @@ -379,7 +385,7 @@ class TerminalViewState extends State<TerminalView> {
widget.terminal.textInput(text);
}

_scrollToBottom();
if (widget.scrollOnInput) _scrollToBottom();
}

void _onComposing(String? text) {
Expand Down Expand Up @@ -419,15 +425,15 @@ class TerminalViewState extends State<TerminalView> {
shift: HardwareKeyboard.instance.isShiftPressed,
);

if (handled) {
if (handled && widget.scrollOnInput) {
_scrollToBottom();
}

return handled ? KeyEventResult.handled : KeyEventResult.ignored;
}

void _onKeyboardShow() {
if (_focusNode.hasFocus) {
if (_focusNode.hasFocus && widget.scrollOnInput) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToBottom();
});
Expand Down