Skip to content

fix: shouldshow of formattingtoolbar #744

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

Merged
merged 1 commit into from
May 21, 2024
Merged
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
@@ -1,4 +1,4 @@
import { isNodeSelection, posToDOMRect } from "@tiptap/core";
import { isNodeSelection, isTextSelection, posToDOMRect } from "@tiptap/core";
import { EditorState, Plugin, PluginKey, PluginView } from "prosemirror-state";
import { EditorView } from "prosemirror-view";

Expand All @@ -22,7 +22,19 @@ export class FormattingToolbarView implements PluginView {
state: EditorState;
from: number;
to: number;
}) => boolean = ({ state }) => !state.selection.empty;
}) => boolean = ({ state, from, to, view }) => {
const { doc, selection } = state;
const { empty } = selection;

// Sometime check for `empty` is not enough.
// Doubleclick an empty paragraph returns a node size of 2.
// So we check also for an empty text size.
const isEmptyTextBlock =
!doc.textBetween(from, to).length && isTextSelection(state.selection);

// check view.hasFocus so that the toolbar doesn't show up when the editor is not focused or when for example a code block is focused
return !(!view.hasFocus() || empty || isEmptyTextBlock);
};

constructor(
private readonly editor: BlockNoteEditor<
Expand Down
Loading