From 6c47417687f7850d016ea9ef32d00a3af5f49fc3 Mon Sep 17 00:00:00 2001 From: primozratej Date: Mon, 5 Aug 2024 18:28:04 +0200 Subject: [PATCH] trim spaces on change --- lib/pages/opener.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/pages/opener.dart b/lib/pages/opener.dart index f8755a5..5daddfb 100644 --- a/lib/pages/opener.dart +++ b/lib/pages/opener.dart @@ -137,6 +137,16 @@ class OpenerState extends ConsumerState with SingleTickerProviderStateMi controlLer.helper.onSaved(controlLer.formUrlKey); _connectInstance(); }, + onChanged: (value) { + // Calculate the new cursor position + final cursorPosition = controlLer.urlTextController.selection.baseOffset; + final trimmedValue = value.trim(); + // Update the text controller and set the new cursor position + controlLer.urlTextController.value = TextEditingValue( + text: trimmedValue, + selection: TextSelection.collapsed(offset: cursorPosition > trimmedValue.length ? trimmedValue.length : cursorPosition), + ); + }, style: const TextStyle( decoration: TextDecoration.none, ),