Skip to content

Commit

Permalink
fix: revert changes to selectAll command, fix #2491
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Feb 7, 2022
1 parent 7f97efb commit bdab760
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/commands/setTextSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const setTextSelection: RawCommands['setTextSelection'] = position => ({
? { from: position, to: position }
: position
const minPos = TextSelection.atStart(doc).from
const maxPos = doc.content.size
const maxPos = TextSelection.atEnd(doc).to
const resolvedFrom = minMax(from, minPos, maxPos)
const resolvedEnd = minMax(to, minPos, maxPos)
const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)
Expand Down
28 changes: 18 additions & 10 deletions packages/core/src/helpers/resolveFocusPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ export function resolveFocusPosition(
return null
}

const selectionAtStart = Selection.atStart(doc)
const selectionAtEnd = Selection.atEnd(doc)

if (position === 'start' || position === true) {
return Selection.atStart(doc)
return selectionAtStart
}

if (position === 'end') {
return Selection.atEnd(doc)
return selectionAtEnd
}

const minPos = selectionAtStart.from
const maxPos = selectionAtEnd.to

if (position === 'all') {
return TextSelection.create(doc, 0, doc.content.size)
return TextSelection.create(
doc,
minMax(0, minPos, maxPos),
minMax(doc.content.size, minPos, maxPos),
)
}

// Check if `position` is in bounds of the doc if `position` is a number.
const minPos = Selection.atStart(doc).from
const maxPos = Selection.atEnd(doc).to
const resolvedFrom = minMax(position, minPos, maxPos)
const resolvedEnd = minMax(position, minPos, maxPos)

return TextSelection.create(doc, resolvedFrom, resolvedEnd)
return TextSelection.create(
doc,
minMax(position, minPos, maxPos),
minMax(position, minPos, maxPos),
)
}

0 comments on commit bdab760

Please sign in to comment.