From 149d57150c732d0927e87f3ee95a73c767973cf9 Mon Sep 17 00:00:00 2001 From: Sahil Yeole Date: Tue, 17 Oct 2023 21:29:05 +0530 Subject: [PATCH] attempt fix text selection Signed-off-by: Sahil Yeole --- flutter/lib/desktop/pages/connection_page.dart | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index db0aaf801..604cd3f93 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -69,12 +69,6 @@ class _ConnectionPageState extends State _updateTimer = periodic_immediate(Duration(seconds: 1), () async { updateStatus(); }); - _idFocusNode.addListener(() { - _idInputFocused.value = _idFocusNode.hasFocus; - // select all to faciliate removing text, just following the behavior of address input of chrome - _idController.selection = TextSelection( - baseOffset: 0, extentOffset: _idController.value.text.length); - }); Get.put(_idController); windowManager.addListener(this); } @@ -289,14 +283,16 @@ class _ConnectionPageState extends State VoidCallback onFieldSubmitted, ) { fieldTextEditingController.text = _idController.text; - fieldFocusNode.addListener(() { + fieldFocusNode.addListener(() async { _idInputFocused.value = fieldFocusNode.hasFocus; if (fieldFocusNode.hasFocus && !isPeersLoading){ _fetchPeers(); } - // select all to faciliate removing text, just following the behavior of address input of chrome - _idController.selection = TextSelection( - baseOffset: 0, extentOffset: _idController.value.text.length); + // select all to facilitate removing text, just following the behavior of address input of chrome + final textLength = fieldTextEditingController.value.text.length; + await Future.delayed(Duration(milliseconds: 200)); + fieldTextEditingController.selection = TextSelection.collapsed(offset: textLength); + fieldTextEditingController.selection = TextSelection(baseOffset: 0, extentOffset: textLength); }); return Obx(() => TextField(