Skip to content

Commit 68503bf

Browse files
authored
Fixed setting of wrong position (#16148)
1 parent 15fbf23 commit 68503bf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

web_src/js/markup/tasklist.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ export function initMarkupTasklist() {
1414
const checkboxes = el.querySelectorAll(`.task-list-item input[type=checkbox]`);
1515

1616
for (const checkbox of checkboxes) {
17-
if (checkbox.dataset.editable) return;
17+
if (checkbox.dataset.editable) {
18+
return;
19+
}
20+
1821
checkbox.dataset.editable = 'true';
1922
checkbox.addEventListener('input', async () => {
2023
const checkboxCharacter = checkbox.checked ? 'x' : ' ';
2124
const position = parseInt(checkbox.dataset.sourcePosition) + 1;
2225

2326
const rawContent = container.querySelector('.raw-content');
2427
const oldContent = rawContent.textContent;
25-
const newContent = oldContent.substring(0, position) + checkboxCharacter + oldContent.substring(position + 1);
26-
if (newContent === oldContent) return;
28+
29+
const encoder = new TextEncoder();
30+
const buffer = encoder.encode(oldContent);
31+
buffer.set(encoder.encode(checkboxCharacter), position);
32+
const newContent = new TextDecoder().decode(buffer);
33+
34+
if (newContent === oldContent) {
35+
return;
36+
}
2737

2838
// Prevent further inputs until the request is done. This does not use the
2939
// `disabled` attribute because it causes the border to flash on click.

0 commit comments

Comments
 (0)