Skip to content

Commit 2da4a89

Browse files
committed
Fix deleting multi-byte character (may not be perfect though)
1 parent 9c1f7e4 commit 2da4a89

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,6 @@ <h3>設定</h3>
21612161
cursor_pos[1] -= len;
21622162
let [node, index, l] = getCursoredNode();
21632163
console.log(node, index, l, len, cursor_pos[1]);
2164-
let tlen = texts[cursor_pos[0]].slice(cursor_pos[1], cursor_pos[1]+len).length;
21652164
texts[cursor_pos[0]] = UTF8String.fromString(texts[cursor_pos[0]].slice(0, cursor_pos[1]) + texts[cursor_pos[0]].slice(cursor_pos[1]+len));
21662165
arr2 = node.innerText.match(/(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF])/g) || [];
21672166
let i = 0;
@@ -2170,8 +2169,8 @@ <h3>設定</h3>
21702169
i2 += (codes[cursor_pos[0]].slice(i2).match(/^(?:<[^>]+>)*(?:(?:&[^;]+;)|[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF])(?:<[^>]+>)*/) || [""])[0].length;
21712170
i += 1;
21722171
}
2173-
console.log(i2, i2+tlen*16, codes[cursor_pos[0]].slice(i2, i2+tlen*16));
2174-
tlen = (codes[cursor_pos[0]].slice(i2, i2+tlen*16).match(/(?:&[^;]+;)|[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || []).slice(0, tlen).join("").length;
2172+
console.log(i2, i2+len*16, codes[cursor_pos[0]].slice(i2, i2+len*16));
2173+
let tlen = (codes[cursor_pos[0]].slice(i2, i2+len*16).match(/(?:&[^;]+;)|[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || []).slice(0, len).join("").length;
21752174
codes[cursor_pos[0]] = (codes[cursor_pos[0]].slice(0, i2) + codes[cursor_pos[0]].slice(i2 + tlen)).replace(/<([^\/> ]+)[^>]*><\/\1[^>]+>/g, "");
21762175
if (node.innerText.length == 0) {
21772176
while (node.innerText.length == 0 && node.tagName != "CODE") {

0 commit comments

Comments
 (0)