Shun Miyazawa 2 лет назад
Родитель
Сommit
c2e723bcf4

+ 1 - 32
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -160,6 +160,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
 
 
   const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.MAIN, previewRef);
   const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.MAIN, previewRef);
+
   const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]);
   const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]);
   const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
   const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
 
 
@@ -272,38 +273,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
 
 
   }, [codeMirrorEditor, pageId]);
   }, [codeMirrorEditor, pageId]);
 
 
-  // const scrollEditorHandler = useCallback(() => {
-  //   if (codeMirrorEditor?.view?.scrollDOM == null || previewRef.current == null) {
-  //     return;
-  //   }
-
-  //   if (isOriginOfScrollSyncPreview) {
-  //     isOriginOfScrollSyncPreview = false;
-  //     return;
-  //   }
-
-  //   isOriginOfScrollSyncEditor = true;
-  //   scrollEditor(codeMirrorEditor.view.scrollDOM, previewRef.current);
-  // }, [codeMirrorEditor]);
-
-  // const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]);
-
-  // const scrollPreviewHandler = useCallback(() => {
-  //   if (codeMirrorEditor?.view?.scrollDOM == null || previewRef.current == null) {
-  //     return;
-  //   }
-
-  //   if (isOriginOfScrollSyncEditor) {
-  //     isOriginOfScrollSyncEditor = false;
-  //     return;
-  //   }
-
-  //   isOriginOfScrollSyncPreview = true;
-  //   scrollPreview(codeMirrorEditor.view.scrollDOM, previewRef.current);
-  // }, [codeMirrorEditor]);
-
-  // const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
-
   // initial caret line
   // initial caret line
   useEffect(() => {
   useEffect(() => {
     codeMirrorEditor?.setCaretLine();
     codeMirrorEditor?.setCaretLine();

+ 4 - 5
apps/app/src/components/PageEditor/PageEditorReadOnly.tsx

@@ -18,17 +18,16 @@ export const PageEditorReadOnly = react.memo((): JSX.Element => {
   const previewRef = useRef<HTMLDivElement>(null);
   const previewRef = useRef<HTMLDivElement>(null);
   const [previewRect] = useRect(previewRef);
   const [previewRect] = useRect(previewRef);
 
 
-  const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.READONLY, previewRef);
-  const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]);
-  const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
-
   const { data: currentPage } = useSWRxCurrentPage();
   const { data: currentPage } = useSWRxCurrentPage();
   const { data: rendererOptions } = usePreviewOptions();
   const { data: rendererOptions } = usePreviewOptions();
   const { data: editingMarkdown } = useEditingMarkdown();
   const { data: editingMarkdown } = useEditingMarkdown();
   const { data: isOldRevisionPage } = useIsOldRevisionPage();
   const { data: isOldRevisionPage } = useIsOldRevisionPage();
-
   const shouldExpandContent = useShouldExpandContent(currentPage);
   const shouldExpandContent = useShouldExpandContent(currentPage);
 
 
+  const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.READONLY, previewRef);
+  const scrollEditorHandlerThrottle = useMemo(() => throttle(25, scrollEditorHandler), [scrollEditorHandler]);
+  const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
+
   const pastEndStyle: CSSProperties | undefined = useMemo(() => {
   const pastEndStyle: CSSProperties | undefined = useMemo(() => {
     if (previewRect == null) {
     if (previewRect == null) {
       return undefined;
       return undefined;