From 0f5f9f65245e40b6c0ebb434308be0fe4b2b129b Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:17:13 +0800 Subject: [PATCH] revert: #9769 (#9780) Not sure TextEditingController.addListener() can handle all composing changes. https://github.com/rustdesk/rustdesk/issues/7727#issuecomment-2445721499 Signed-off-by: fufesou --- flutter/lib/mobile/pages/remote_page.dart | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index a8446de20..40890f228 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -57,7 +57,9 @@ class _RemotePageState extends State { final TextEditingController _textController = TextEditingController(text: initText); - bool _lastComposingChangeValid = false; + // This timer is used to check the composing status of the soft keyboard. + // It is used for Android, Korean(and other similar) input method. + Timer? _composingTimer; _RemotePageState(String id) { initSharedStates(id); @@ -97,9 +99,6 @@ class _RemotePageState extends State { showToast(translate('Automatically record outgoing sessions')); } }); - if (isAndroid) { - _textController.addListener(textAndroidListener); - } } @override @@ -115,6 +114,7 @@ class _RemotePageState extends State { _physicalFocusNode.dispose(); await gFFI.close(); _timer?.cancel(); + _composingTimer?.cancel(); gFFI.dialogManager.dismissAll(); await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values); @@ -127,16 +127,6 @@ class _RemotePageState extends State { // The inner logic of `on_voice_call_closed` will check if the voice call is active. // Only one client is considered here for now. gFFI.chatModel.onVoiceCallClosed("End connetion"); - if (isAndroid) { - _textController.removeListener(textAndroidListener); - } - } - - // This listener is used to handle the composing region changes for Android soft keyboard input. - void textAndroidListener() { - if (_lastComposingChangeValid) { - _handleNonIOSSoftKeyboardInput(_textController.text); - } } // to-do: It should be better to use transparent color instead of the bgColor. @@ -160,6 +150,7 @@ class _RemotePageState extends State { gFFI.ffiModel.pi.version.isNotEmpty) { gFFI.invokeMethod("enable_soft_keyboard", false); } + _composingTimer?.cancel(); } else { _timer?.cancel(); _timer = Timer(kMobileDelaySoftKeyboardFocus, () { @@ -223,8 +214,11 @@ class _RemotePageState extends State { } void _handleNonIOSSoftKeyboardInput(String newValue) { - _lastComposingChangeValid = _textController.value.isComposingRangeValid; - if (_lastComposingChangeValid) { + _composingTimer?.cancel(); + if (_textController.value.isComposingRangeValid) { + _composingTimer = Timer(Duration(milliseconds: 25), () { + _handleNonIOSSoftKeyboardInput(_textController.value.text); + }); return; } var oldValue = _value;