Răsfoiți Sursa

auto focus for untitled page in first rendering

reiji-h 2 ani în urmă
părinte
comite
7825c02d20
1 a modificat fișierele cu 9 adăugiri și 7 ștergeri
  1. 9 7
      apps/app/src/components/PageEditor/PageEditor.tsx

+ 9 - 7
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -273,11 +273,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
 
   }, [codeMirrorEditor, pageId]);
 
-  // initial caret line
-  useEffect(() => {
-    codeMirrorEditor?.setCaretLine();
-  }, [codeMirrorEditor]);
-
   // set handler to save and return to View
   useEffect(() => {
     globalEmitter.on('saveAndReturnToView', saveAndReturnToViewHandler);
@@ -287,12 +282,19 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
     };
   }, [saveAndReturnToViewHandler]);
 
+
+  // TODO: https://redmine.weseek.co.jp/issues/142729
+  // https://regex101.com/r/Wg2Hh6/1
   // set handler to focus
   useLayoutEffect(() => {
-    if (editorMode === EditorMode.Editor) {
+    const untitledPageRegex = /^Untitled-\d+$/;
+    const isNewlyCreatedPage = (
+      currentPage?.wip && currentPage?.latestRevision == null && untitledPageRegex.test(nodePath.basename(currentPage?.path ?? ''))
+    ) ?? false;
+    if (editorMode === EditorMode.Editor && !isNewlyCreatedPage) {
       codeMirrorEditor?.focus();
     }
-  }, [codeMirrorEditor, editorMode]);
+  }, [codeMirrorEditor, editorMode, currentPage]);
 
   // Detect indent size from contents (only when users are allowed to change it)
   useEffect(() => {