fix: return text field to the previous state after editing message
closes #9
This commit is contained in:
parent
687c0aba1d
commit
a2c13cc4bd
|
@ -97,6 +97,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 {
|
||||||
|
@ -201,12 +203,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 = '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +356,19 @@ class _ChatState extends State<_Chat> {
|
||||||
inputFocus.requestFocus();
|
inputFocus.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void editAction(Event event) {
|
||||||
|
setState(() {
|
||||||
|
pendingText = sendController.text;
|
||||||
|
editEvent = event;
|
||||||
|
inputText = sendController.text = editEvent
|
||||||
|
.getDisplayEvent(timeline)
|
||||||
|
.getLocalizedBody(MatrixLocals(L10n.of(context)),
|
||||||
|
withSenderNamePrefix: false, hideReply: true);
|
||||||
|
selectedEvents.clear();
|
||||||
|
});
|
||||||
|
inputFocus.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void _scrollToEventId(String eventId, {BuildContext context}) async {
|
void _scrollToEventId(String eventId, {BuildContext context}) async {
|
||||||
var eventIndex =
|
var eventIndex =
|
||||||
getFilteredEvents().indexWhere((e) => e.eventId == eventId);
|
getFilteredEvents().indexWhere((e) => e.eventId == eventId);
|
||||||
|
@ -521,15 +537,7 @@ class _ChatState extends State<_Chat> {
|
||||||
forwardEventsAction(context, event: event);
|
forwardEventsAction(context, event: event);
|
||||||
break;
|
break;
|
||||||
case 'edit':
|
case 'edit':
|
||||||
setState(() {
|
editAction(event);
|
||||||
editEvent = event;
|
|
||||||
sendController.text = editEvent
|
|
||||||
.getDisplayEvent(timeline)
|
|
||||||
.getLocalizedBody(MatrixLocals(L10n.of(context)),
|
|
||||||
withSenderNamePrefix: false, hideReply: true);
|
|
||||||
selectedEvents.clear();
|
|
||||||
});
|
|
||||||
inputFocus.requestFocus();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -643,17 +651,7 @@ class _ChatState extends State<_Chat> {
|
||||||
selectedEvents.first.senderId == client.userID)
|
selectedEvents.first.senderId == client.userID)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.edit),
|
icon: Icon(Icons.edit),
|
||||||
onPressed: () {
|
onPressed: () => editAction(selectedEvents.first),
|
||||||
setState(() {
|
|
||||||
editEvent = selectedEvents.first;
|
|
||||||
sendController.text = editEvent
|
|
||||||
.getDisplayEvent(timeline)
|
|
||||||
.getLocalizedBody(MatrixLocals(L10n.of(context)),
|
|
||||||
withSenderNamePrefix: false, hideReply: true);
|
|
||||||
selectedEvents.clear();
|
|
||||||
});
|
|
||||||
inputFocus.requestFocus();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.content_copy),
|
icon: Icon(Icons.content_copy),
|
||||||
|
@ -910,6 +908,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;
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue