Skip to content

Commit 49e1ac7

Browse files
committed
chore(core): improve content-editable experience
1 parent b0fb670 commit 49e1ac7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/core/src/effects/useContentEditableEffect.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function placeCaretAtEnd(el: HTMLInputElement, isCollapse: boolean) {
1414
el.focus()
1515
const range = document.createRange()
1616
range.selectNodeContents(el)
17-
if (!isCollapse) {
17+
if (isCollapse) {
1818
range.collapse(false)
1919
}
2020
const sel = window.getSelection()
@@ -45,13 +45,14 @@ export const useContentEditableEffect = (engine: Engine) => {
4545
clearTimeout(globalState.requestTimer)
4646
globalState.requestTimer = setTimeout(() => {
4747
if (globalState.isComposition) return
48+
const isCollapsed = window.getSelection().isCollapsed
4849
Path.setIn(
4950
node.props,
5051
this.getAttribute(engine.props.contentEditableAttrName),
5152
target?.textContent
5253
)
5354
setTimeout(() => {
54-
placeCaretAtEnd(this, window.getSelection().isCollapsed)
55+
placeCaretAtEnd(this, isCollapsed)
5556
}, 16)
5657
}, 1000)
5758
}

0 commit comments

Comments
 (0)