Skip to content

Commit 03345ce

Browse files
committed
Remove redundant selection clearing and space insertion logic from blur and ghost text handling
1 parent 889e7b5 commit 03345ce

2 files changed

Lines changed: 2 additions & 27 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/PromptField.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
408408
onDragOver={handle_drag_over}
409409
onDragEnd={handle_drag_end}
410410
onFocus={() => set_is_focused(true)}
411-
onBlur={() => {
412-
set_is_focused(false)
413-
window.getSelection()?.removeAllRanges()
414-
}}
411+
onBlur={() => set_is_focused(false)}
415412
className={cn(styles.input, {
416413
[styles['input--empty']]: !props.value
417414
})}

‎packages/ui/src/components/editor/panel/PromptField/hooks/use-ghost-text.ts‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,32 +185,10 @@ export const use_ghost_text = ({
185185
if (parent_node) {
186186
parent_node.replaceChild(text_node, ghost_node)
187187

188-
let next_sibling = text_node.nextSibling
189-
let space_added = false
190-
191-
if (
192-
!next_sibling ||
193-
next_sibling.nodeType !== Node.TEXT_NODE ||
194-
!next_sibling.textContent?.startsWith(' ')
195-
) {
196-
const space_node = document.createTextNode(' ')
197-
if (next_sibling) {
198-
parent_node.insertBefore(space_node, next_sibling)
199-
} else {
200-
parent_node.appendChild(space_node)
201-
}
202-
next_sibling = space_node
203-
space_added = true
204-
}
205-
206188
const selection = window.getSelection()
207189
if (selection) {
208190
const range = document.createRange()
209-
if (space_added) {
210-
range.setStartAfter(next_sibling!)
211-
} else {
212-
range.setStart(next_sibling!, 1)
213-
}
191+
range.setStartAfter(text_node)
214192
range.collapse(true)
215193
selection.removeAllRanges()
216194
selection.addRange(range)

0 commit comments

Comments
 (0)