diff --git a/packages/core/client/src/schema-component/antd/variable/TextArea.tsx b/packages/core/client/src/schema-component/antd/variable/TextArea.tsx index 27ea75ee2..1367d8e8e 100644 --- a/packages/core/client/src/schema-component/antd/variable/TextArea.tsx +++ b/packages/core/client/src/schema-component/antd/variable/TextArea.tsx @@ -229,19 +229,21 @@ export function TextArea(props) { const sel = window.getSelection?.(); if (sel) { const children = Array.from(current.childNodes) as HTMLElement[]; - if (range[0] === -1) { - if (range[1]) { - nextRange.setStartAfter(children[range[1] - 1]); + if (children.length) { + if (range[0] === -1) { + if (range[1]) { + nextRange.setStartAfter(children[range[1] - 1]); + } + } else { + nextRange.setStart(children[range[0]], range[1]); } - } else { - nextRange.setStart(children[range[0]], range[1]); - } - if (range[2] === -1) { - if (range[3]) { - nextRange.setEndAfter(children[range[3] - 1]); + if (range[2] === -1) { + if (range[3]) { + nextRange.setEndAfter(children[range[3] - 1]); + } + } else { + nextRange.setEnd(children[range[2]], range[3]); } - } else { - nextRange.setEnd(children[range[2]], range[3]); } nextRange.collapse(true); sel.removeAllRanges();