fix(client): fix varaible textarea setRange bug (#2862)

This commit is contained in:
Junyi 2023-10-19 16:02:52 +08:00 committed by GitHub
parent 0e9ab35254
commit 9cbae661b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,19 +229,21 @@ export function TextArea(props) {
const sel = window.getSelection?.(); const sel = window.getSelection?.();
if (sel) { if (sel) {
const children = Array.from(current.childNodes) as HTMLElement[]; const children = Array.from(current.childNodes) as HTMLElement[];
if (range[0] === -1) { if (children.length) {
if (range[1]) { if (range[0] === -1) {
nextRange.setStartAfter(children[range[1] - 1]); if (range[1]) {
nextRange.setStartAfter(children[range[1] - 1]);
}
} else {
nextRange.setStart(children[range[0]], range[1]);
} }
} else { if (range[2] === -1) {
nextRange.setStart(children[range[0]], range[1]); if (range[3]) {
} nextRange.setEndAfter(children[range[3] - 1]);
if (range[2] === -1) { }
if (range[3]) { } else {
nextRange.setEndAfter(children[range[3] - 1]); nextRange.setEnd(children[range[2]], range[3]);
} }
} else {
nextRange.setEnd(children[range[2]], range[3]);
} }
nextRange.collapse(true); nextRange.collapse(true);
sel.removeAllRanges(); sel.removeAllRanges();