mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 19:17:58 +00:00
refact: Remote ID editor, only select text on focus (#10854)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -8,13 +8,16 @@ import 'package:flutter_hbb/common/widgets/peer_card.dart';
|
|||||||
class AllPeersLoader {
|
class AllPeersLoader {
|
||||||
List<Peer> peers = [];
|
List<Peer> peers = [];
|
||||||
|
|
||||||
bool isPeersLoading = false;
|
bool _isPeersLoading = false;
|
||||||
bool isPeersLoaded = false;
|
bool _isPeersLoaded = false;
|
||||||
|
|
||||||
final String _listenerKey = 'AllPeersLoader';
|
final String _listenerKey = 'AllPeersLoader';
|
||||||
|
|
||||||
late void Function(VoidCallback) setState;
|
late void Function(VoidCallback) setState;
|
||||||
|
|
||||||
|
bool get needLoad => !_isPeersLoaded && !_isPeersLoading;
|
||||||
|
bool get isPeersLoaded => _isPeersLoaded;
|
||||||
|
|
||||||
AllPeersLoader();
|
AllPeersLoader();
|
||||||
|
|
||||||
void init(void Function(VoidCallback) setState) {
|
void init(void Function(VoidCallback) setState) {
|
||||||
@@ -33,10 +36,10 @@ class AllPeersLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getAllPeers() async {
|
Future<void> getAllPeers() async {
|
||||||
if (isPeersLoaded || isPeersLoading) {
|
if (!needLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isPeersLoading = true;
|
_isPeersLoading = true;
|
||||||
|
|
||||||
if (gFFI.recentPeersModel.peers.isEmpty) {
|
if (gFFI.recentPeersModel.peers.isEmpty) {
|
||||||
bind.mainLoadRecentPeers();
|
bind.mainLoadRecentPeers();
|
||||||
@@ -96,8 +99,8 @@ class AllPeersLoader {
|
|||||||
|
|
||||||
peers = parsedPeers;
|
peers = parsedPeers;
|
||||||
setState(() {
|
setState(() {
|
||||||
isPeersLoading = false;
|
_isPeersLoading = false;
|
||||||
isPeersLoaded = true;
|
_isPeersLoaded = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,8 +282,15 @@ class _ConnectionPageState extends State<ConnectionPage>
|
|||||||
|
|
||||||
void onFocusChanged() {
|
void onFocusChanged() {
|
||||||
_idInputFocused.value = _idFocusNode.hasFocus;
|
_idInputFocused.value = _idFocusNode.hasFocus;
|
||||||
if (_idFocusNode.hasFocus && !_allPeersLoader.isPeersLoading) {
|
if (_idFocusNode.hasFocus) {
|
||||||
_allPeersLoader.getAllPeers();
|
if (_allPeersLoader.needLoad) {
|
||||||
|
_allPeersLoader.getAllPeers();
|
||||||
|
}
|
||||||
|
|
||||||
|
final textLength = _idEditingController.value.text.length;
|
||||||
|
// Select all to facilitate removing text, just following the behavior of address input of chrome.
|
||||||
|
_idEditingController.selection =
|
||||||
|
TextSelection(baseOffset: 0, extentOffset: textLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,17 +397,6 @@ class _ConnectionPageState extends State<ConnectionPage>
|
|||||||
) {
|
) {
|
||||||
fieldTextEditingController.text = _idController.text;
|
fieldTextEditingController.text = _idController.text;
|
||||||
Get.put<TextEditingController>(fieldTextEditingController);
|
Get.put<TextEditingController>(fieldTextEditingController);
|
||||||
|
|
||||||
// The listener will be added multiple times when the widget is rebuilt.
|
|
||||||
// We may need to use the `RawAutocomplete` to get the focus node.
|
|
||||||
|
|
||||||
// Temporarily remove Selection because Selection can cause users to accidentally delete previously entered content during input.
|
|
||||||
// final textLength =
|
|
||||||
// fieldTextEditingController.value.text.length;
|
|
||||||
// // Select all to facilitate removing text, just following the behavior of address input of chrome.
|
|
||||||
// fieldTextEditingController.selection =
|
|
||||||
// TextSelection(baseOffset: 0, extentOffset: textLength);
|
|
||||||
|
|
||||||
return Obx(() => TextField(
|
return Obx(() => TextField(
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
|
|||||||
@@ -104,8 +104,15 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
|
|
||||||
void onFocusChanged() {
|
void onFocusChanged() {
|
||||||
_idEmpty.value = _idEditingController.text.isEmpty;
|
_idEmpty.value = _idEditingController.text.isEmpty;
|
||||||
if (_idFocusNode.hasFocus && !_allPeersLoader.isPeersLoading) {
|
if (_idFocusNode.hasFocus) {
|
||||||
_allPeersLoader.getAllPeers();
|
if (_allPeersLoader.needLoad) {
|
||||||
|
_allPeersLoader.getAllPeers();
|
||||||
|
}
|
||||||
|
|
||||||
|
final textLength = _idEditingController.value.text.length;
|
||||||
|
// Select all to facilitate removing text, just following the behavior of address input of chrome.
|
||||||
|
_idEditingController.selection =
|
||||||
|
TextSelection(baseOffset: 0, extentOffset: textLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,14 +217,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
fieldTextEditingController.text = _idController.text;
|
fieldTextEditingController.text = _idController.text;
|
||||||
Get.put<TextEditingController>(
|
Get.put<TextEditingController>(
|
||||||
fieldTextEditingController);
|
fieldTextEditingController);
|
||||||
|
|
||||||
// Temporarily remove Selection because Selection can cause users to accidentally delete previously entered content during input.
|
|
||||||
// final textLength =
|
|
||||||
// fieldTextEditingController.value.text.length;
|
|
||||||
// // select all to facilitate removing text, just following the behavior of address input of chrome
|
|
||||||
// fieldTextEditingController.selection = TextSelection(
|
|
||||||
// baseOffset: 0, extentOffset: textLength);
|
|
||||||
|
|
||||||
return AutoSizeTextField(
|
return AutoSizeTextField(
|
||||||
controller: fieldTextEditingController,
|
controller: fieldTextEditingController,
|
||||||
focusNode: fieldFocusNode,
|
focusNode: fieldFocusNode,
|
||||||
|
|||||||
Reference in New Issue
Block a user