fix(web): keep editable text stable while typing
All checks were successful
CI / test (push) Successful in 21s
All checks were successful
CI / test (push) Successful in 21s
This commit is contained in:
@@ -37,6 +37,7 @@ export function MessageComposer() {
|
|||||||
const pointerMoveHandlerRef = useRef<((event: globalThis.PointerEvent) => void) | null>(null);
|
const pointerMoveHandlerRef = useRef<((event: globalThis.PointerEvent) => void) | null>(null);
|
||||||
const pointerUpHandlerRef = useRef<((event: globalThis.PointerEvent) => void) | null>(null);
|
const pointerUpHandlerRef = useRef<((event: globalThis.PointerEvent) => void) | null>(null);
|
||||||
const recordingStateRef = useRef<RecordingState>("idle");
|
const recordingStateRef = useRef<RecordingState>("idle");
|
||||||
|
const lastEditingMessageIdRef = useRef<number | null>(null);
|
||||||
|
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
const [uploadProgress, setUploadProgress] = useState(0);
|
const [uploadProgress, setUploadProgress] = useState(0);
|
||||||
@@ -73,20 +74,22 @@ export function MessageComposer() {
|
|||||||
if (text !== "") {
|
if (text !== "") {
|
||||||
setText("");
|
setText("");
|
||||||
}
|
}
|
||||||
|
lastEditingMessageIdRef.current = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (editingMessage) {
|
if (editingMessage) {
|
||||||
const editingText = editingMessage.text ?? "";
|
if (lastEditingMessageIdRef.current !== editingMessage.id) {
|
||||||
if (text !== editingText) {
|
setText(editingMessage.text ?? "");
|
||||||
setText(editingText);
|
|
||||||
}
|
}
|
||||||
|
lastEditingMessageIdRef.current = editingMessage.id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
lastEditingMessageIdRef.current = null;
|
||||||
const draft = draftsByChat[activeChatId] ?? "";
|
const draft = draftsByChat[activeChatId] ?? "";
|
||||||
if (draft !== text) {
|
if (draft !== text) {
|
||||||
setText(draft);
|
setText(draft);
|
||||||
}
|
}
|
||||||
}, [activeChatId, draftsByChat, text, editingMessage]);
|
}, [activeChatId, draftsByChat, editingMessage, text]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user