Skip to content

Commit

Permalink
fix: Side menu scrolling (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlipski authored Jan 27, 2025
1 parent 844de93 commit 4d2fe51
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/extensions/SideMenu/SideMenuPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ export class SideMenuView<
this.onKeyDown as EventListener,
true
);

// Setting capture=true ensures that any parent container of the editor that
// gets scrolled will trigger the scroll event. Scroll events do not bubble
// and so won't propagate to the document by default.
pmView.root.addEventListener("scroll", this.onScroll, true);
}

updateState = (state: SideMenuState<BSchema, I, S>) => {
Expand Down Expand Up @@ -473,6 +478,13 @@ export class SideMenuView<
return evt;
}

onScroll = () => {
if (this.state?.show) {
this.state.referencePos = this.hoveredBlock!.getBoundingClientRect();
this.emitUpdate(this.state);
}
};

// Needed in cases where the editor state updates without the mouse cursor
// moving, as some state updates can require a side menu update. For example,
// adding a button to the side menu which removes the block can cause the
Expand Down Expand Up @@ -515,6 +527,7 @@ export class SideMenuView<
this.onKeyDown as EventListener,
true
);
this.pmView.root.removeEventListener("scroll", this.onScroll, true);
}
}

Expand Down

0 comments on commit 4d2fe51

Please sign in to comment.