Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Jul 18, 2022
1 parent b966f0c commit 84c673a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/document/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,22 @@ export function commitValueAfterInput(

element[TrackChanges] = undefined

if (!changes?.tracked?.length) {
return
}

const isJustReactStateUpdate =
changes?.tracked?.length === 2 &&
changes.tracked.length === 2 &&
changes.tracked[0] === changes.previousValue &&
changes.tracked[1] === element.value

if (isJustReactStateUpdate) {
if (hasUISelection(element)) {
setUISelection(element, {focusOffset: cursorOffset})
}
} else if (changes?.tracked?.length) {
if (!isJustReactStateUpdate) {
setUIValueClean(element)
if (hasUISelection(element)) {
setUISelection(element, {focusOffset: element.value.length})
}
}

if (hasUISelection(element)) {
setUISelection(element, {
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length,
})
}
}

0 comments on commit 84c673a

Please sign in to comment.