Skip to content

Commit

Permalink
fix(core): setNodeSelection should not clamp pos by Selection.atStart…
Browse files Browse the repository at this point in the history
…/atEnd (#3091)

Fixes #3090.
  • Loading branch information
kivikakk authored Aug 22, 2022
1 parent cc1395a commit 313b8b8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/core/src/commands/setNodeSelection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeSelection, Selection } from 'prosemirror-state'
import { NodeSelection } from 'prosemirror-state'

import { RawCommands } from '../types'
import { minMax } from '../utilities/minMax'
Expand All @@ -17,10 +17,8 @@ declare module '@tiptap/core' {
export const setNodeSelection: RawCommands['setNodeSelection'] = position => ({ tr, dispatch }) => {
if (dispatch) {
const { doc } = tr
const minPos = Selection.atStart(doc).from
const maxPos = Selection.atEnd(doc).to
const resolvedPos = minMax(position, minPos, maxPos)
const selection = NodeSelection.create(doc, resolvedPos)
const from = minMax(position, 0, doc.content.size)
const selection = NodeSelection.create(doc, from)

tr.setSelection(selection)
}
Expand Down

0 comments on commit 313b8b8

Please sign in to comment.