Skip to content

Commit

Permalink
Merge pull request #244 from pangeachat/toolbar-fixes
Browse files Browse the repository at this point in the history
Fixing toolbar bugs for newly-sent messages
  • Loading branch information
ggurdin authored May 27, 2024
2 parents 62d221c + 9a66134 commit 4f96c55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
6 changes: 1 addition & 5 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ class MessageContent extends StatelessWidget {
MatrixLocals(L10n.of(context)!),
hideReply: true,
);
toolbarController?.toolbar?.textSelection.setMessageText(
messageText,
);
return SelectableLinkify(
onSelectionChanged: (selection, cause) {
if (cause == SelectionChangedCause.longPress &&
Expand All @@ -363,8 +360,7 @@ class MessageContent extends StatelessWidget {
.onTextSelection(selection);
},
onTap: () => toolbarController?.showToolbar(context),
text: toolbarController?.toolbar?.textSelection.messageText ??
messageText,
text: messageText,
contextMenuBuilder: (context, state) =>
(toolbarController?.highlighted ?? false)
? const SizedBox.shrink()
Expand Down
21 changes: 13 additions & 8 deletions lib/pangea/widgets/chat/message_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ class MessageToolbarState extends State<MessageToolbar> {
return;
}

setState(() {
currentMode = newMode;
updatingMode = true;
});
if (mounted) {
setState(() {
currentMode = newMode;
updatingMode = true;
});
}

if (!subscribed) {
toolbarContent = MessageUnsubscribedCard(
languageTool: newMode.title(context),
Expand Down Expand Up @@ -221,9 +224,11 @@ class MessageToolbarState extends State<MessageToolbar> {
break;
}
}
setState(() {
updatingMode = false;
});
if (mounted) {
setState(() {
updatingMode = false;
});
}
}

void showTranslation() {
Expand Down Expand Up @@ -289,7 +294,7 @@ class MessageToolbarState extends State<MessageToolbar> {
final bool autoplay = MatrixState.pangeaController.pStoreService.read(
PLocalKey.autoPlayMessages,
) ??
true;
false;

if (widget.pangeaMessageEvent.isAudioMessage) {
updateMode(MessageMode.speechToText);
Expand Down
4 changes: 3 additions & 1 deletion lib/pangea/widgets/chat/message_translation_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
l2Code = MatrixState.pangeaController.languageController.activeL2Code(
roomID: widget.messageEvent.room.id,
);
setState(() {});
if (mounted) {
setState(() {});
}

loadTranslation(() async {
if (widget.selection.selectedText != null) {
Expand Down
8 changes: 5 additions & 3 deletions lib/pangea/widgets/igc/pangea_rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class PangeaRichTextState extends State<PangeaRichText> {
widget.toolbarController?.toolbar?.textSelection.setMessageText(
newTextSpan,
);
setState(() {
textSpan = newTextSpan;
});
if (mounted) {
setState(() {
textSpan = newTextSpan;
});
}
}

void setTextSpan() {
Expand Down

0 comments on commit 4f96c55

Please sign in to comment.