added scrollintoviewifneeded to the pages if one is focused off screen, also added to focus block so that the block comes into view if you arrow up or down to focus it
···3434import { CardThemeProvider } from "../ThemeManager/ThemeProvider";
3535import { PageShareMenu } from "./PageShareMenu";
3636import { Watermark } from "components/Watermark";
3737+import { scrollIntoViewIfNeeded } from "src/utils/scrollIntoViewIfNeeded";
37383839export function Pages(props: { rootPage: string }) {
3940 let rootPage = useEntity(props.rootPage, "root/page")[0];
···366367367368 setTimeout(async () => {
368369 //scroll to page
369369- document.getElementById(elementId.page(pageID).container)?.scrollIntoView({
370370- behavior: "smooth",
371371- inline: "nearest",
372372- });
370370+371371+ scrollIntoViewIfNeeded(
372372+ document.getElementById(elementId.page(pageID).container),
373373+ false,
374374+ "smooth",
375375+ );
373376374377 // if we asked that the function focus the first block, focus the first block
375378 if (focusFirstBlock === "focusFirstBlock") {
+11
src/utils/focusBlock.ts
···11import { TextSelection } from "prosemirror-state";
22import { useUIState } from "src/useUIState";
33import { Block } from "components/Blocks/Block";
44+import { elementId } from "src/utils/elementId";
4556import { setEditorState, useEditorStates } from "src/state/useEditorState";
77+import { scrollIntoViewIfNeeded } from "./scrollIntoViewIfNeeded";
6879export function focusBlock(
810 block: Pick<Block, "type" | "value" | "parent">,
911 position: Position,
1012) {
1313+ // focus the block
1114 useUIState.getState().setSelectedBlock(block);
1215 useUIState.getState().setFocusedBlock({
1316 entityType: "block",
1417 entityID: block.value,
1518 parent: block.parent,
1619 });
2020+ scrollIntoViewIfNeeded(
2121+ document.getElementById(elementId.block(block.value).container),
2222+ false,
2323+ );
2424+2525+ // if its not a text block, that's all we need to do
1726 if (block.type !== "text" && block.type !== "heading") {
1827 return true;
1928 }
2929+ // if its a text block, and not an empty block that is last on the page,
3030+ // focus the editor using the mouse position if needed
2031 let nextBlockID = block.value;
2132 let nextBlock = useEditorStates.getState().editorStates[nextBlockID];
2233 if (!nextBlock || !nextBlock.view) return;
+6-1
src/utils/scrollIntoViewIfNeeded.ts
···11export function scrollIntoViewIfNeeded(
22 el: Element | null,
33 centerIfNeeded: boolean = true,
44+ behavior?: ScrollBehavior,
45) {
55- if (!el) return;
66+ if (!el) {
77+ return;
88+ }
69 let observer = new IntersectionObserver(function ([entry]) {
710 const ratio = entry.intersectionRatio;
1111+812 if (ratio < 1) {
913 let place =
1014 ratio <= 0 && centerIfNeeded
···1317 el.scrollIntoView({
1418 block: place,
1519 inline: place,
2020+ behavior: behavior ? behavior : "auto",
1621 });
1722 }
1823 observer.disconnect();