Merge branch 'better-edit-cancel' into 'main'

fix: return text field to the previous state after editing message

Closes #196

See merge request ChristianPauly/fluffychat-flutter!234
This commit is contained in:
Christian Pauly 2020-10-23 15:45:23 +00:00
commit 9130e841f8
2 changed files with 12 additions and 3 deletions

View file

@ -18,6 +18,7 @@
- Show device name in account information correctly - Show device name in account information correctly
- Fix tapping on aliases / room pills not always working - Fix tapping on aliases / room pills not always working
- Link clicking in web not always working - Link clicking in web not always working
- Return message input field to previous state after editing message - Thanks @inexcode
# Version 0.19.0 - 2020-09-21 # Version 0.19.0 - 2020-09-21
### Features ### Features

View file

@ -98,6 +98,8 @@ class _ChatState extends State<_Chat> {
String inputText = ''; String inputText = '';
String pendingText = '';
bool get _canLoadMore => timeline.events.last.type != EventTypes.RoomCreate; bool get _canLoadMore => timeline.events.last.type != EventTypes.RoomCreate;
void requestHistory() async { void requestHistory() async {
@ -202,12 +204,13 @@ class _ChatState extends State<_Chat> {
if (sendController.text.isEmpty) return; if (sendController.text.isEmpty) return;
room.sendTextEvent(sendController.text, room.sendTextEvent(sendController.text,
inReplyTo: replyEvent, editEventId: editEvent?.eventId); inReplyTo: replyEvent, editEventId: editEvent?.eventId);
sendController.text = ''; sendController.text = pendingText;
setState(() { setState(() {
inputText = ''; inputText = pendingText;
replyEvent = null; replyEvent = null;
editEvent = null; editEvent = null;
pendingText = '';
}); });
} }
@ -522,8 +525,9 @@ class _ChatState extends State<_Chat> {
icon: Icon(Icons.edit), icon: Icon(Icons.edit),
onPressed: () { onPressed: () {
setState(() { setState(() {
pendingText = sendController.text;
editEvent = selectedEvents.first; editEvent = selectedEvents.first;
sendController.text = editEvent inputText = sendController.text = editEvent
.getDisplayEvent(timeline) .getDisplayEvent(timeline)
.getLocalizedBody(MatrixLocals(L10n.of(context)), .getLocalizedBody(MatrixLocals(L10n.of(context)),
withSenderNamePrefix: false, hideReply: true); withSenderNamePrefix: false, hideReply: true);
@ -787,6 +791,10 @@ class _ChatState extends State<_Chat> {
IconButton( IconButton(
icon: Icon(Icons.close), icon: Icon(Icons.close),
onPressed: () => setState(() { onPressed: () => setState(() {
if (editEvent != null) {
inputText = sendController.text = pendingText;
pendingText = '';
}
replyEvent = null; replyEvent = null;
editEvent = null; editEvent = null;
}), }),