From 7bd18f5dec758c82e25946e251da27fc934fe5dc Mon Sep 17 00:00:00 2001 From: Br1an <932039080@qq.com> Date: Thu, 16 Apr 2026 11:58:34 +0800 Subject: [PATCH] fix(editor): restore focus to main textbox after editing a post (#35518) After editing a post, the main textbox now properly regains focus. The fix uses the stored refocusId to focus the correct textbox element (post_textbox or reply_textbox) before unsetting edit mode. Co-authored-by: Mattermost Build --- .../src/components/advanced_text_editor/use_submit.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webapp/channels/src/components/advanced_text_editor/use_submit.tsx b/webapp/channels/src/components/advanced_text_editor/use_submit.tsx index 27258c56f68..975da538d14 100644 --- a/webapp/channels/src/components/advanced_text_editor/use_submit.tsx +++ b/webapp/channels/src/components/advanced_text_editor/use_submit.tsx @@ -119,6 +119,8 @@ const useSubmit = ( return haveIChannelPermission(state, channel.team_id, channel.id, Permissions.USE_CHANNEL_MENTIONS); }); + const editingPostRefocusId = useSelector((state: GlobalState) => state.views.posts.editingPost.refocusId); + const showPostDeletedModal = useCallback(() => { dispatch(openModal({ modalId: ModalIdentifiers.POST_DELETED_MODAL, @@ -236,6 +238,11 @@ const useSubmit = ( } if (isInEditMode) { + // Refocus the main textbox before unsetting edit mode + if (editingPostRefocusId) { + const element = document.getElementById(editingPostRefocusId); + element?.focus(); + } dispatch(unsetEditingPost()); } @@ -258,6 +265,7 @@ const useSubmit = ( channelId, isInEditMode, handleFileChange, + editingPostRefocusId, ]); const setUpdatedFileIds = useCallback((draft: PostDraft) => {