diff --git a/app/components/Sidebar/components/NavLink.tsx b/app/components/Sidebar/components/NavLink.tsx index 16b5cfcc4..ab15f98ac 100644 --- a/app/components/Sidebar/components/NavLink.tsx +++ b/app/components/Sidebar/components/NavLink.tsx @@ -62,7 +62,7 @@ const NavLink = ({ to, ...rest }: Props) => { - const linkRef = React.useRef(null); + const linkRef = React.useRef(null); const context = React.useContext(RouterContext); const [preActive, setPreActive] = React.useState( undefined @@ -93,10 +93,18 @@ const NavLink = ({ React.useLayoutEffect(() => { if (isActive && linkRef.current && scrollIntoViewIfNeeded !== false) { - scrollIntoView(linkRef.current, { - scrollMode: "if-needed", - behavior: "auto", - }); + // If the page has an anchor hash then this means we're linking to an + // anchor in the document generally – smooth scrolling the sidebar may + // interrupt the scrolling to the anchor of the document so we jump + // directly to the anchor instead. + if (window.location.hash) { + linkRef.current.scrollIntoView(); + } else { + scrollIntoView(linkRef.current, { + scrollMode: "if-needed", + behavior: "auto", + }); + } } }, [linkRef, scrollIntoViewIfNeeded, isActive]); diff --git a/app/editor/components/SuggestionsMenu.tsx b/app/editor/components/SuggestionsMenu.tsx index 263fc955a..a9ced29d9 100644 --- a/app/editor/components/SuggestionsMenu.tsx +++ b/app/editor/components/SuggestionsMenu.tsx @@ -166,7 +166,7 @@ function SuggestionsMenu(props: Props) { const handleClearSearch = React.useCallback(() => { const { state, dispatch } = view; const poss = state.doc.cut( - state.selection.from - (props.search ?? "").length - 1, + state.selection.from - (props.search ?? "").length - props.trigger.length, state.selection.from ); const trimTrigger = poss.textContent.startsWith(props.trigger); @@ -181,7 +181,7 @@ function SuggestionsMenu(props: Props) { "", state.selection.from - (props.search ?? "").length - - (trimTrigger ? 1 : 0), + (trimTrigger ? props.trigger.length : 0), state.selection.to ) );