Skip to content

Commit 9ffeedd

Browse files
authored
Fix focus when replying to messages (#623)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Recaptures input box focus when replying to a message. Fixes #621 #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
2 parents 8c62746 + fe09f2a commit 9ffeedd

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
Fix reply button not capturing editor focus.

src/app/features/room/RoomInput.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
419419
}
420420
}, [mentionInReplies, mx, replyDraft]);
421421

422+
const prevReplyEventId = useRef(replyDraft?.eventId);
423+
useEffect(() => {
424+
if (replyDraft?.eventId !== prevReplyEventId.current) {
425+
prevReplyEventId.current = replyDraft?.eventId;
426+
427+
if (replyDraft?.eventId) {
428+
requestAnimationFrame(() => {
429+
try {
430+
ReactEditor.focus(editor);
431+
moveCursor(editor);
432+
} catch {
433+
// Ignore focus errors
434+
}
435+
});
436+
}
437+
}
438+
}, [replyDraft?.eventId, editor]);
439+
422440
const handleFileMetadata = useCallback(
423441
(fileItem: TUploadItem, metadata: TUploadMetadata) => {
424442
setSelectedFiles({

0 commit comments

Comments
 (0)