Skip to content

Commit a4b7f36

Browse files
fix: getSelection behaviour and build (#1318)
1 parent 5e4389c commit a4b7f36

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/core/src/api/blockManipulation/selections/selection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ export function getSelection<
2323
): Selection<BSchema, I, S> | undefined {
2424
const state = editor._tiptapEditor.state;
2525

26+
// Return undefined if the selection is collapsed or a node is selected.
27+
if (state.selection.empty || "node" in state.selection) {
28+
return undefined;
29+
}
30+
2631
const $startBlockBeforePos = state.doc.resolve(
2732
getNearestBlockPos(state.doc, state.selection.from).posBeforeNode
2833
);
2934
const $endBlockBeforePos = state.doc.resolve(
3035
getNearestBlockPos(state.doc, state.selection.to).posBeforeNode
3136
);
3237

33-
// Return undefined if anchor and head are in the same block.
34-
if ($startBlockBeforePos.pos === $endBlockBeforePos.pos) {
35-
return undefined;
36-
}
37-
3838
// Converts the node at the given index and depth around `$startBlockBeforePos`
3939
// to a block. Used to get blocks at given indices at the shared depth and
4040
// at the depth of `$startBlockBeforePos`.

packages/react/src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ export const CreateLinkButton = () => {
6666
}
6767
};
6868

69-
editor.prosemirrorView.dom.addEventListener("keydown", callback);
69+
editor.prosemirrorView?.dom.addEventListener("keydown", callback);
7070

7171
return () => {
72-
editor.prosemirrorView.dom.removeEventListener("keydown", callback);
72+
editor.prosemirrorView?.dom.removeEventListener("keydown", callback);
7373
};
74-
}, [editor.prosemirrorView.dom]);
74+
}, [editor.prosemirrorView?.dom]);
7575

7676
const update = useCallback(
7777
(url: string, text: string) => {

0 commit comments

Comments
 (0)