Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: remove some formattingtoolbar listeners #1254

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,8 @@ export class FormattingToolbarView implements PluginView {

pmView.dom.addEventListener("mousedown", this.viewMousedownHandler);
pmView.dom.addEventListener("mouseup", this.viewMouseupHandler);
pmView.dom.addEventListener("dragstart", this.dragHandler);
pmView.dom.addEventListener("dragover", this.dragHandler);
pmView.dom.addEventListener("blur", this.blurHandler);

// 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.scrollHandler, true);
}

blurHandler = (event: FocusEvent) => {
if (this.preventHide) {
this.preventHide = false;

return;
}

const editorWrapper = this.pmView.dom.parentElement!;

// Checks if the focus is moving to an element outside the editor. If it is,
// the toolbar is hidden.
if (
// An element is clicked.
event &&
event.relatedTarget &&
// Element is inside the editor.
(editorWrapper === (event.relatedTarget as Node) ||
editorWrapper.contains(event.relatedTarget as Node) ||
(event.relatedTarget as HTMLElement).matches(
".bn-ui-container, .bn-ui-container *"
))
) {
return;
}

if (this.state?.show) {
this.state.show = false;
this.emitUpdate();
}
};

viewMousedownHandler = () => {
this.preventShow = true;
};
Expand All @@ -118,21 +79,6 @@ export class FormattingToolbarView implements PluginView {
setTimeout(() => this.update(this.pmView));
};

// For dragging the whole editor.
dragHandler = () => {
if (this.state?.show) {
this.state.show = false;
this.emitUpdate();
}
};

scrollHandler = () => {
if (this.state?.show) {
this.state.referencePos = this.getSelectionBoundingBox();
this.emitUpdate();
}
};

update(view: EditorView, oldState?: EditorState) {
// Delays the update to handle edge case with drag and drop, where the view
// is blurred asynchronously and happens only after the state update.
Expand Down Expand Up @@ -192,11 +138,6 @@ export class FormattingToolbarView implements PluginView {
destroy() {
this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler);
this.pmView.dom.removeEventListener("mouseup", this.viewMouseupHandler);
this.pmView.dom.removeEventListener("dragstart", this.dragHandler);
this.pmView.dom.removeEventListener("dragover", this.dragHandler);
this.pmView.dom.removeEventListener("blur", this.blurHandler);

this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
}

closeMenu = () => {
Expand Down
Loading