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