Skip to content
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