Skip to content

Commit 3aac0ce

Browse files
committed
feat(core): improve content editable
1 parent c7868ba commit 3aac0ce

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/core/src/effects/useContentEditableEffect.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ type GlobalState = {
88
}
99

1010
function placeCaretAtEnd(el: HTMLInputElement) {
11+
const currentSelection = window.getSelection()
12+
if (currentSelection.containsNode(el)) return
1113
el.focus()
12-
let range = document.createRange()
14+
const range = document.createRange()
1315
range.selectNodeContents(el)
1416
range.collapse(false)
15-
let sel = window.getSelection()
17+
const sel = window.getSelection()
1618
sel.removeAllRanges()
1719
sel.addRange(range)
1820
}
@@ -46,7 +48,7 @@ export const useContentEditableEffect = (engine: Engine) => {
4648
setTimeout(() => {
4749
placeCaretAtEnd(this)
4850
}, 16)
49-
}, 1000)
51+
}, 300)
5052
}
5153
}
5254

packages/react/src/theme.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@
243243
}
244244

245245
*[contenteditable='true'] {
246-
display: block !important;
246+
display: block;
247247
min-width: 1px;
248-
min-height: 14px !important;
248+
min-height: 14px;
249249
cursor: text !important;
250250
outline: none !important;
251251
}

0 commit comments

Comments
 (0)