From 365b7f0a12a4c5c7fd3422428ff07f0c17b0ac8f Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:08:32 -0500 Subject: [PATCH] fix: resolve issues with token punctuation combination and HWL activities (#2051) --- .../events/utils/message_text_util.dart | 6 +- lib/pangea/login/pages/pangea_login_view.dart | 65 ++++++++++--------- .../toolbar/widgets/message_token_text.dart | 51 +++++++-------- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/lib/pangea/events/utils/message_text_util.dart b/lib/pangea/events/utils/message_text_util.dart index 7c829dba3..a230648ef 100644 --- a/lib/pangea/events/utils/message_text_util.dart +++ b/lib/pangea/events/utils/message_text_util.dart @@ -36,9 +36,6 @@ class MessageTextUtil { final int startIndex = messageCharacters.take(start).length; int endIndex = messageCharacters.take(end).length; - final hideContent = - messageAnalyticsEntry?.isTokenInHiddenWordActivity(token) ?? false; - final hasHiddenContent = messageAnalyticsEntry?.hasHiddenWordActivity ?? false; @@ -80,6 +77,9 @@ class MessageTextUtil { break; } + final hideContent = + messageAnalyticsEntry?.isTokenInHiddenWordActivity(token) ?? false; + tokenPositions.add( TokenPosition( start: startIndex, diff --git a/lib/pangea/login/pages/pangea_login_view.dart b/lib/pangea/login/pages/pangea_login_view.dart index 05efcefaf..3c219fd67 100644 --- a/lib/pangea/login/pages/pangea_login_view.dart +++ b/lib/pangea/login/pages/pangea_login_view.dart @@ -20,38 +20,41 @@ class PangeaLoginView extends StatelessWidget { child: PangeaLoginScaffold( children: [ AutofillGroup( - child: Column(children: [ - FullWidthTextField( - hintText: L10n.of(context).username, - autofillHints: const [AutofillHints.username], - autoFocus: true, - textInputAction: TextInputAction.next, - validator: (value) { - if (value == null || value.isEmpty) { - return L10n.of(context).pleaseEnterYourUsername; - } - return null; - }, - controller: controller.usernameController, + child: Column( + children: [ + FullWidthTextField( + hintText: L10n.of(context).username, + autofillHints: const [AutofillHints.username], + autoFocus: true, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return L10n.of(context).pleaseEnterYourUsername; + } + return null; + }, + controller: controller.usernameController, + ), + FullWidthTextField( + hintText: L10n.of(context).password, + autofillHints: const [AutofillHints.password], + autoFocus: true, + obscureText: true, + textInputAction: TextInputAction.go, + onSubmitted: (_) { + controller.enabledSignIn ? controller.login() : null; + }, + validator: (value) { + if (value == null || value.isEmpty) { + return L10n.of(context).pleaseEnterYourPassword; + } + return null; + }, + controller: controller.passwordController, + ), + ], ), - FullWidthTextField( - hintText: L10n.of(context).password, - autofillHints: const [AutofillHints.password], - autoFocus: true, - obscureText: true, - textInputAction: TextInputAction.go, - onSubmitted: (_) { - controller.enabledSignIn ? controller.login() : null; - }, - validator: (value) { - if (value == null || value.isEmpty) { - return L10n.of(context).pleaseEnterYourPassword; - } - return null; - }, - controller: controller.passwordController, - ), - ])), + ), FullWidthButton( title: L10n.of(context).signIn, icon: PangeaLogoSvg( diff --git a/lib/pangea/toolbar/widgets/message_token_text.dart b/lib/pangea/toolbar/widgets/message_token_text.dart index 3738b9530..0a9f66702 100644 --- a/lib/pangea/toolbar/widgets/message_token_text.dart +++ b/lib/pangea/toolbar/widgets/message_token_text.dart @@ -235,17 +235,6 @@ class MessageTextWidget extends StatelessWidget { } if (tokenPosition.token != null) { - if (tokenPosition.hideContent) { - return WidgetSpan( - child: GestureDetector( - onTap: onClick != null - ? () => onClick?.call(tokenPosition) - : null, - child: HiddenText(text: substring, style: style), - ), - ); - } - // if the tokenPosition is a combination of the token and preceding / following punctuation // split them so that only the token itself is highlighted when clicked String start = ''; @@ -260,7 +249,7 @@ class MessageTextWidget extends StatelessWidget { end = substring.characters.skip(endSplitIndex).toString(); middle = substring.characters .skip(startSplitIndex) - .take(endSplitIndex) + .take(endSplitIndex - startSplitIndex) .toString(); return WidgetSpan( @@ -284,20 +273,30 @@ class MessageTextWidget extends StatelessWidget { onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), ), - LinkifySpan( - text: middle, - style: style.merge( - TextStyle( - backgroundColor: backgroundColor, - ), - ), - linkStyle: TextStyle( - decoration: TextDecoration.underline, - color: linkColor, - ), - onOpen: (url) => - UrlLauncher(context, url.url).launchUrl(), - ), + tokenPosition.hideContent + ? WidgetSpan( + alignment: PlaceholderAlignment.middle, + child: GestureDetector( + onTap: onClick != null + ? () => onClick?.call(tokenPosition) + : null, + child: HiddenText(text: middle, style: style), + ), + ) + : LinkifySpan( + text: middle, + style: style.merge( + TextStyle( + backgroundColor: backgroundColor, + ), + ), + linkStyle: TextStyle( + decoration: TextDecoration.underline, + color: linkColor, + ), + onOpen: (url) => + UrlLauncher(context, url.url).launchUrl(), + ), if (end.isNotEmpty) LinkifySpan( text: end,