From 08da254bae57872471fa3a221832e14b2bf5f7d9 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Thu, 18 Jul 2024 16:33:54 -0400 Subject: [PATCH 1/4] Input text turns red when hit limit --- lib/pages/chat/input_bar.dart | 3 +++ lib/pangea/widgets/chat/input_bar_wrapper.dart | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 9337b488a..0d2251203 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -504,6 +504,9 @@ class InputBar extends StatelessWidget { onSubmitted!(text); }, // #Pangea + style: controller?.text.length == 1000 + ? const TextStyle(color: Colors.red) + : null, onTap: () { controller!.onInputTap( context, diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 374f60a80..5f6c1b49b 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -61,6 +61,11 @@ class InputBarWrapperState extends State { super.dispose(); } + void refreshOnChange(String text) { + widget.onChanged!(text); + setState(() {}); + } + @override Widget build(BuildContext context) { return InputBar( @@ -73,7 +78,7 @@ class InputBarWrapperState extends State { focusNode: widget.focusNode, controller: widget.controller, decoration: widget.decoration, - onChanged: widget.onChanged, + onChanged: widget.onChanged != null ? refreshOnChange : null, autofocus: widget.autofocus, textInputAction: widget.textInputAction, readOnly: widget.readOnly, From 828b406286926f622cac999e70d345687d24c95c Mon Sep 17 00:00:00 2001 From: Kelrap Date: Mon, 22 Jul 2024 10:04:18 -0400 Subject: [PATCH 2/4] Only rebuild when maxLength changes --- lib/pages/chat/input_bar.dart | 14 +++++++++++--- lib/pangea/widgets/chat/input_bar_wrapper.dart | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 0d2251203..4ffde1f42 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -21,6 +21,7 @@ class InputBar extends StatelessWidget { final ValueChanged? onSubmitImage; final FocusNode? focusNode; // #Pangea + final Function? updateBar; // final TextEditingController? controller; final PangeaTextController? controller; // Pangea# @@ -38,6 +39,7 @@ class InputBar extends StatelessWidget { this.onSubmitImage, this.focusNode, this.controller, + this.updateBar, this.decoration, this.onChanged, this.autofocus, @@ -401,6 +403,9 @@ class InputBar extends StatelessWidget { @override Widget build(BuildContext context) { final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile); + // #Pangea + final bool maxLength = controller?.text.length == 1000; + // Pangea# return Shortcuts( shortcuts: !useShortCuts ? {} @@ -504,9 +509,7 @@ class InputBar extends StatelessWidget { onSubmitted!(text); }, // #Pangea - style: controller?.text.length == 1000 - ? const TextStyle(color: Colors.red) - : null, + style: maxLength ? const TextStyle(color: Colors.red) : null, onTap: () { controller!.onInputTap( context, @@ -519,6 +522,11 @@ class InputBar extends StatelessWidget { // fix for the library for now // it sets the types for the callback incorrectly onChanged!(text); + // #Pangea + if (maxLength != (controller?.text.length == 1000)) { + updateBar!(); + } + // Pangea# }, textCapitalization: TextCapitalization.sentences, ), diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 5f6c1b49b..5aa813bbe 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -61,8 +61,7 @@ class InputBarWrapperState extends State { super.dispose(); } - void refreshOnChange(String text) { - widget.onChanged!(text); + void refreshOnChange() { setState(() {}); } @@ -78,7 +77,8 @@ class InputBarWrapperState extends State { focusNode: widget.focusNode, controller: widget.controller, decoration: widget.decoration, - onChanged: widget.onChanged != null ? refreshOnChange : null, + updateBar: refreshOnChange, + onChanged: widget.onChanged, autofocus: widget.autofocus, textInputAction: widget.textInputAction, readOnly: widget.readOnly, From 8c1df0eb88c85c663e0e0f4f28c015b297ff4533 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Tue, 23 Jul 2024 12:35:53 -0400 Subject: [PATCH 3/4] Move calculations to state --- lib/pages/chat/input_bar.dart | 13 ++++--------- lib/pangea/widgets/chat/input_bar_wrapper.dart | 13 +++++++++---- lib/pangea/widgets/igc/pangea_text_controller.dart | 5 +++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 4ffde1f42..54dba8674 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -21,7 +21,6 @@ class InputBar extends StatelessWidget { final ValueChanged? onSubmitImage; final FocusNode? focusNode; // #Pangea - final Function? updateBar; // final TextEditingController? controller; final PangeaTextController? controller; // Pangea# @@ -39,7 +38,6 @@ class InputBar extends StatelessWidget { this.onSubmitImage, this.focusNode, this.controller, - this.updateBar, this.decoration, this.onChanged, this.autofocus, @@ -404,7 +402,7 @@ class InputBar extends StatelessWidget { Widget build(BuildContext context) { final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile); // #Pangea - final bool maxLength = controller?.text.length == 1000; + controller?.currentlyMaxLength = controller?.isMaxLength ?? false; // Pangea# return Shortcuts( shortcuts: !useShortCuts @@ -509,7 +507,9 @@ class InputBar extends StatelessWidget { onSubmitted!(text); }, // #Pangea - style: maxLength ? const TextStyle(color: Colors.red) : null, + style: controller?.isMaxLength ?? false + ? const TextStyle(color: Colors.red) + : null, onTap: () { controller!.onInputTap( context, @@ -522,11 +522,6 @@ class InputBar extends StatelessWidget { // fix for the library for now // it sets the types for the callback incorrectly onChanged!(text); - // #Pangea - if (maxLength != (controller?.text.length == 1000)) { - updateBar!(); - } - // Pangea# }, textCapitalization: TextCapitalization.sentences, ), diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 5aa813bbe..1e8cd4727 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -61,8 +61,14 @@ class InputBarWrapperState extends State { super.dispose(); } - void refreshOnChange() { - setState(() {}); + void refreshOnChange(String text) { + if (widget.onChanged != null) { + widget.onChanged!(text); + } + if (widget.controller?.currentlyMaxLength != + widget.controller?.isMaxLength) { + setState(() {}); + } } @override @@ -77,8 +83,7 @@ class InputBarWrapperState extends State { focusNode: widget.focusNode, controller: widget.controller, decoration: widget.decoration, - updateBar: refreshOnChange, - onChanged: widget.onChanged, + onChanged: refreshOnChange, autofocus: widget.autofocus, textInputAction: widget.textInputAction, readOnly: widget.readOnly, diff --git a/lib/pangea/widgets/igc/pangea_text_controller.dart b/lib/pangea/widgets/igc/pangea_text_controller.dart index b91186c22..d7f24a7e2 100644 --- a/lib/pangea/widgets/igc/pangea_text_controller.dart +++ b/lib/pangea/widgets/igc/pangea_text_controller.dart @@ -25,6 +25,11 @@ class PangeaTextController extends TextEditingController { text ??= ''; this.text = text; } + + bool get isMaxLength => text.length == 1000; + + bool currentlyMaxLength = false; + bool forceKeepOpen = false; setSystemText(String text, EditType type) { From 6311df08756d919cf50fd9707e83133b7db5492b Mon Sep 17 00:00:00 2001 From: ggurdin Date: Thu, 25 Jul 2024 11:25:59 -0400 Subject: [PATCH 4/4] moved stateful variable from text controller to input bar wrapper widget --- lib/pages/chat/input_bar.dart | 3 --- lib/pangea/widgets/chat/input_bar_wrapper.dart | 13 +++++++++++-- lib/pangea/widgets/igc/pangea_text_controller.dart | 3 +-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 54dba8674..84a802e54 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -401,9 +401,6 @@ class InputBar extends StatelessWidget { @override Widget build(BuildContext context) { final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile); - // #Pangea - controller?.currentlyMaxLength = controller?.isMaxLength ?? false; - // Pangea# return Shortcuts( shortcuts: !useShortCuts ? {} diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 1e8cd4727..9441312bd 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -44,6 +44,7 @@ class InputBarWrapper extends StatefulWidget { class InputBarWrapperState extends State { StreamSubscription? _choreoSub; + String _currentText = ''; @override void initState() { @@ -65,10 +66,18 @@ class InputBarWrapperState extends State { if (widget.onChanged != null) { widget.onChanged!(text); } - if (widget.controller?.currentlyMaxLength != - widget.controller?.isMaxLength) { + + final bool decreasedFromMaxLength = + _currentText.length >= PangeaTextController.maxLength && + text.length < PangeaTextController.maxLength; + final bool reachedMaxLength = + _currentText.length < PangeaTextController.maxLength && + text.length < PangeaTextController.maxLength; + + if (decreasedFromMaxLength || reachedMaxLength) { setState(() {}); } + _currentText = text; } @override diff --git a/lib/pangea/widgets/igc/pangea_text_controller.dart b/lib/pangea/widgets/igc/pangea_text_controller.dart index d7f24a7e2..8fc136edd 100644 --- a/lib/pangea/widgets/igc/pangea_text_controller.dart +++ b/lib/pangea/widgets/igc/pangea_text_controller.dart @@ -26,10 +26,9 @@ class PangeaTextController extends TextEditingController { this.text = text; } + static const int maxLength = 1000; bool get isMaxLength => text.length == 1000; - bool currentlyMaxLength = false; - bool forceKeepOpen = false; setSystemText(String text, EditType type) {