Skip to content

Fix issue with checkbox checking and unicode #16148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions web_src/js/markup/tasklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ 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' : ' ';
const position = parseInt(checkbox.dataset.sourcePosition) + 1;

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.
Expand Down