From 84355d122ef6677cce6011d3bb4bf87bb6040bab Mon Sep 17 00:00:00 2001 From: nightmare Date: Thu, 29 Feb 2024 18:07:49 +0800 Subject: [PATCH] fix: Fix terminal cannot input 'enter' on android --- lib/src/terminal_view.dart | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/src/terminal_view.dart b/lib/src/terminal_view.dart index cf2c3c3..d5f519f 100644 --- a/lib/src/terminal_view.dart +++ b/lib/src/terminal_view.dart @@ -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'; @@ -163,8 +162,7 @@ class TerminalViewState extends State { late ScrollController _scrollController; - RenderTerminal get renderTerminal => - _viewportKey.currentContext!.findRenderObject() as RenderTerminal; + RenderTerminal get renderTerminal => _viewportKey.currentContext!.findRenderObject() as RenderTerminal; @override void initState() { @@ -265,7 +263,8 @@ class TerminalViewState extends State { 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); } }, @@ -301,10 +300,8 @@ class TerminalViewState extends State { 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, ); @@ -336,8 +333,7 @@ class TerminalViewState extends State { } Rect get globalCursorRect { - return renderTerminal.localToGlobal(renderTerminal.cursorOffset) & - renderTerminal.cellSize; + return renderTerminal.localToGlobal(renderTerminal.cursorOffset) & renderTerminal.cellSize; } void _onTapUp(TapUpDetails details) {