mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
fix(page): should only do focus on init load
This commit is contained in:
@@ -130,6 +130,7 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
|
|||||||
const contentEditorRef = useRef<LAEditorRef>(null)
|
const contentEditorRef = useRef<LAEditorRef>(null)
|
||||||
const isTitleInitialMount = useRef(true)
|
const isTitleInitialMount = useRef(true)
|
||||||
const isContentInitialMount = useRef(true)
|
const isContentInitialMount = useRef(true)
|
||||||
|
const isInitialFocusApplied = useRef(false)
|
||||||
|
|
||||||
const updatePageContent = (content: Content, model: PersonalPage) => {
|
const updatePageContent = (content: Content, model: PersonalPage) => {
|
||||||
if (isContentInitialMount.current) {
|
if (isContentInitialMount.current) {
|
||||||
@@ -201,7 +202,6 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
|
|||||||
|
|
||||||
const titleEditor = useEditor({
|
const titleEditor = useEditor({
|
||||||
immediatelyRender: false,
|
immediatelyRender: false,
|
||||||
autofocus: false,
|
|
||||||
extensions: [
|
extensions: [
|
||||||
FocusClasses,
|
FocusClasses,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
@@ -246,10 +246,13 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
|
|||||||
isTitleInitialMount.current = true
|
isTitleInitialMount.current = true
|
||||||
isContentInitialMount.current = true
|
isContentInitialMount.current = true
|
||||||
|
|
||||||
if (!page.title) {
|
if (!isInitialFocusApplied.current && titleEditor && contentEditorRef.current?.editor) {
|
||||||
titleEditor?.commands.focus()
|
isInitialFocusApplied.current = true
|
||||||
} else {
|
if (!page.title) {
|
||||||
contentEditorRef.current?.editor?.commands.focus()
|
titleEditor?.commands.focus()
|
||||||
|
} else {
|
||||||
|
contentEditorRef.current.editor.commands.focus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [page.title, titleEditor, contentEditorRef])
|
}, [page.title, titleEditor, contentEditorRef])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user