Skip to content

Commit

Permalink
fix: Fix terminal cannot input 'enter' on android
Browse files Browse the repository at this point in the history
  • Loading branch information
mengyanshou committed Feb 29, 2024
1 parent 4266ec2 commit 84355d1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/src/terminal_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:xterm/src/core/buffer/cell_offset.dart';

import 'package:xterm/src/core/input/keys.dart';
import 'package:xterm/src/terminal.dart';
import 'package:xterm/src/ui/controller.dart';
Expand Down Expand Up @@ -163,8 +162,7 @@ class TerminalViewState extends State<TerminalView> {

late ScrollController _scrollController;

RenderTerminal get renderTerminal =>
_viewportKey.currentContext!.findRenderObject() as RenderTerminal;
RenderTerminal get renderTerminal => _viewportKey.currentContext!.findRenderObject() as RenderTerminal;

@override
void initState() {
Expand Down Expand Up @@ -265,7 +263,8 @@ class TerminalViewState extends State<TerminalView> {
onComposing: _onComposing,
onAction: (action) {
_scrollToBottom();
if (action == TextInputAction.done) {
// 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 @@ -301,10 +300,8 @@ class TerminalViewState extends State<TerminalView> {
terminalController: _controller,
onTapUp: _onTapUp,
onTapDown: _onTapDown,
onSecondaryTapDown:
widget.onSecondaryTapDown != null ? _onSecondaryTapDown : null,
onSecondaryTapUp:
widget.onSecondaryTapUp != null ? _onSecondaryTapUp : null,
onSecondaryTapDown: widget.onSecondaryTapDown != null ? _onSecondaryTapDown : null,
onSecondaryTapUp: widget.onSecondaryTapUp != null ? _onSecondaryTapUp : null,
readOnly: widget.readOnly,
child: child,
);
Expand Down Expand Up @@ -336,8 +333,7 @@ class TerminalViewState extends State<TerminalView> {
}

Rect get globalCursorRect {
return renderTerminal.localToGlobal(renderTerminal.cursorOffset) &
renderTerminal.cellSize;
return renderTerminal.localToGlobal(renderTerminal.cursorOffset) & renderTerminal.cellSize;
}

void _onTapUp(TapUpDetails details) {
Expand Down

0 comments on commit 84355d1

Please sign in to comment.