make composer revert to unedited content when dismissing edit, plus more fixes
This commit is contained in:
parent
7f71adab4c
commit
2ed2443298
2 changed files with 43 additions and 23 deletions
|
|
@ -35,7 +35,7 @@ class const Composer(
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final controller = useRef(FlutterTaggerController());
|
final controller = useMemoized(FlutterTaggerController.new);
|
||||||
final triggerCharacter = useState("");
|
final triggerCharacter = useState("");
|
||||||
final shouldMention = useState(true);
|
final shouldMention = useState(true);
|
||||||
final query = useState("");
|
final query = useState("");
|
||||||
|
|
@ -59,15 +59,34 @@ class const Composer(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (relationType == .edit && controller.value.text.isEmpty) {
|
final textBefore = useState<String?>(null);
|
||||||
controller.value.text =
|
|
||||||
relatedEvent?.localContent?.editSource ??
|
useEffect(() {
|
||||||
switch (relatedEvent?.content) {
|
if (relationType == .edit && relatedEvent != null) {
|
||||||
|
textBefore.value ??= controller.text;
|
||||||
|
|
||||||
|
final text =
|
||||||
|
relatedEvent.localContent?.editSource ??
|
||||||
|
switch (relatedEvent.content) {
|
||||||
TextMessageContent(:final body) => body,
|
TextMessageContent(:final body) => body,
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
controller.value = .new(
|
||||||
|
text: text,
|
||||||
|
selection: .collapsed(offset: text.length),
|
||||||
|
);
|
||||||
|
} else if (textBefore.value case final draft?) {
|
||||||
|
controller.value = .new(
|
||||||
|
text: draft,
|
||||||
|
selection: .collapsed(offset: draft.length),
|
||||||
|
);
|
||||||
|
textBefore.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}, [relationType, relatedEvent == null]);
|
||||||
|
|
||||||
final attachment = ref.watch(AttachmentController.provider(roomId));
|
final attachment = ref.watch(AttachmentController.provider(roomId));
|
||||||
|
|
||||||
void send() {
|
void send() {
|
||||||
|
|
@ -76,13 +95,13 @@ class const Composer(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onSend(
|
onSend(
|
||||||
controller.value.formattedText,
|
controller.formattedText,
|
||||||
shouldMention: shouldMention.value,
|
shouldMention: shouldMention.value,
|
||||||
tags: .new(controller.value.tags),
|
tags: .new(controller.tags),
|
||||||
);
|
);
|
||||||
|
|
||||||
onDismiss();
|
onDismiss();
|
||||||
controller.value.text = "";
|
controller.text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final style = TextStyle(
|
final style = TextStyle(
|
||||||
|
|
@ -143,7 +162,7 @@ class const Composer(
|
||||||
builder: (context) => EmojiPicker(
|
builder: (context) => EmojiPicker(
|
||||||
onSelection: (value) {
|
onSelection: (value) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
controller.value.text += value;
|
controller.text += value;
|
||||||
node?.requestFocus();
|
node?.requestFocus();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -161,7 +180,7 @@ class const Composer(
|
||||||
leading: Icon(Icons.add_a_photo),
|
leading: Icon(Icons.add_a_photo),
|
||||||
),
|
),
|
||||||
onTap: () async => ref
|
onTap: () async => ref
|
||||||
.watch(
|
.read(
|
||||||
AttachmentController.provider(roomId)
|
AttachmentController.provider(roomId)
|
||||||
.notifier,
|
.notifier,
|
||||||
)
|
)
|
||||||
|
|
@ -180,7 +199,7 @@ class const Composer(
|
||||||
leading: Icon(Icons.add_photo_alternate),
|
leading: Icon(Icons.add_photo_alternate),
|
||||||
),
|
),
|
||||||
onTap: () async => ref
|
onTap: () async => ref
|
||||||
.watch(
|
.read(
|
||||||
AttachmentController.provider(roomId)
|
AttachmentController.provider(roomId)
|
||||||
.notifier,
|
.notifier,
|
||||||
)
|
)
|
||||||
|
|
@ -218,11 +237,11 @@ class const Composer(
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
triggerCharacter: triggerCharacter.value,
|
triggerCharacter: triggerCharacter.value,
|
||||||
addTag: ({required id, required name}) {
|
addTag: ({required id, required name}) {
|
||||||
controller.value.addTag(id: id, name: name);
|
controller.addTag(id: id, name: name);
|
||||||
node?.requestFocus();
|
node?.requestFocus();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
controller: controller.value,
|
controller: controller,
|
||||||
onSearch: (newQuery, newTriggerCharacter) {
|
onSearch: (newQuery, newTriggerCharacter) {
|
||||||
triggerCharacter.value = newTriggerCharacter;
|
triggerCharacter.value = newTriggerCharacter;
|
||||||
query.value = newQuery;
|
query.value = newQuery;
|
||||||
|
|
@ -255,14 +274,12 @@ class const Composer(
|
||||||
autofocus:
|
autofocus:
|
||||||
(Platform.isLinux ||
|
(Platform.isLinux ||
|
||||||
Platform.isMacOS ||
|
Platform.isMacOS ||
|
||||||
Platform.isWindows)
|
Platform.isWindows),
|
||||||
? true
|
|
||||||
: false,
|
|
||||||
decoration: .new(
|
decoration: .new(
|
||||||
hintText: "Your message here...",
|
hintText: "Your message here...",
|
||||||
border: .none,
|
border: .none,
|
||||||
),
|
),
|
||||||
controller: controller.value,
|
controller: controller,
|
||||||
key: key,
|
key: key,
|
||||||
focusNode: node,
|
focusNode: node,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,10 @@ final class const RoomChat({
|
||||||
.onError(showError),
|
.onError(showError),
|
||||||
relationType: relationType.value,
|
relationType: relationType.value,
|
||||||
relatedEvent: relatedEvent.value,
|
relatedEvent: relatedEvent.value,
|
||||||
onDismiss: () => relatedEvent.value = null,
|
onDismiss: () {
|
||||||
|
relatedEvent.value = null;
|
||||||
|
composerNode.requestFocus();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue