Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: scroll blocks into view only for active editor

Abdullah Attac847ca0817bb
diff --git a/packages/editor/src/utils/toc.ts b/packages/editor/src/utils/toc.ts
index 6ff192f66..986ac62f1 100644
--- a/packages/editor/src/utils/toc.ts
+++ b/packages/editor/src/utils/toc.ts
@@ -46,13 +46,20 @@ export function getTableOfContents(content: HTMLElement) {
return tableOfContents;
}
-export function scrollIntoViewById(id: string) {
- const element = document.querySelector(`[data-block-id="${id}"]`);
+export function scrollIntoViewById(blockId: string) {
+ const element = document.querySelector(
+ `.active [data-block-id=${JSON.stringify(blockId)}]`
+ );
+
if (element) {
- element.scrollIntoView({
- behavior: "smooth",
- block: "center",
- inline: "nearest"
- });
+ setTimeout(
+ () =>
+ element.scrollIntoView({
+ behavior: "smooth",
+ block: "center",
+ inline: "nearest"
+ }),
+ 100
+ );
}
}