diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-06-14 22:42:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 22:42:58 +0200 |
commit | 68503bfae6920f1449a1ea432c7b3f422cf780f6 (patch) | |
tree | 60c1fd7eccfcfa8cdae72d0b54bc1562950034c9 /web_src | |
parent | 15fbf23d13e7e03fa0e335ec7d0d539e60ab78d6 (diff) | |
download | gitea-68503bfae6920f1449a1ea432c7b3f422cf780f6.tar.gz gitea-68503bfae6920f1449a1ea432c7b3f422cf780f6.zip |
Fixed setting of wrong position (#16148)
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/markup/tasklist.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index 5a7291b4d0..24b29ddb7a 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -14,7 +14,10 @@ export function initMarkupTasklist() { const checkboxes = el.querySelectorAll(`.task-list-item input[type=checkbox]`); for (const checkbox of checkboxes) { - if (checkbox.dataset.editable) return; + if (checkbox.dataset.editable) { + return; + } + checkbox.dataset.editable = 'true'; checkbox.addEventListener('input', async () => { const checkboxCharacter = checkbox.checked ? 'x' : ' '; @@ -22,8 +25,15 @@ export function initMarkupTasklist() { const rawContent = container.querySelector('.raw-content'); const oldContent = rawContent.textContent; - const newContent = oldContent.substring(0, position) + checkboxCharacter + oldContent.substring(position + 1); - if (newContent === oldContent) return; + + const encoder = new TextEncoder(); + const buffer = encoder.encode(oldContent); + buffer.set(encoder.encode(checkboxCharacter), position); + const newContent = new TextDecoder().decode(buffer); + + if (newContent === oldContent) { + return; + } // Prevent further inputs until the request is done. This does not use the // `disabled` attribute because it causes the border to flash on click. |