Mao 4 лет назад
Родитель
Сommit
09a1353d1e

+ 2 - 2
packages/app/src/client/util/smooth-scroll.ts

@@ -1,6 +1,6 @@
 const WIKI_HEADER_LINK = 120;
 
-export const smoothScrollIntoView = (element: HTMLElement, offsetTop = 0): void => {
+export const smoothScrollIntoView = (element: HTMLElement, offsetTop = 0, startFrom : HTMLElement | Window = window): void => {
   const targetElement = element || window.document.body;
 
   // get the distance to the target element top
@@ -8,7 +8,7 @@ export const smoothScrollIntoView = (element: HTMLElement, offsetTop = 0): void
 
   const top = window.pageYOffset + rectTop - offsetTop;
 
-  window.scrollTo({
+  startFrom.scrollTo({
     top,
     behavior: 'smooth',
   });

+ 4 - 3
packages/app/src/components/Sidebar/PageTree/ItemsTree.tsx

@@ -95,10 +95,11 @@ const ItemsTree: FC<ItemsTreeProps> = (props: ItemsTreeProps) => {
   const { data: ancestorsChildrenData, error: error1 } = useSWRxPageAncestorsChildren(targetPath);
   const { data: rootPageData, error: error2 } = useSWRxRootPage();
 
+  const startFrom = document.getElementById('grw-sidebar-contents-scroll-target');
   const targetElem = document.getElementsByClassName('grw-pagetree-is-target');
-  // targetElem is HTML collection but only one target HTML element in it always
-  if (targetElem[0] != null) {
-    smoothScrollIntoView(targetElem[0] as HTMLElement);
+  //  targetElem is HTML collection but only one HTML element in it all the time
+  if (targetElem[0] != null && startFrom != null) {
+    smoothScrollIntoView(targetElem[0] as HTMLElement, 0, startFrom);
   }
 
   const DeleteModal = (