From 7f8be22e97a29eb54f22aff1ea377973417d45d4 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Wed, 5 May 2021 23:34:03 +0200 Subject: Fix click handler for numbered task lists The regex for tasklists in 1.x didn't include upper-case x/X letters nor ordered lists (1. [ ] abc). This commit changes the regex to allow both. Signed-off-by: Erik Michelson --- public/js/extra.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 7f06ebda..c71475b5 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -266,9 +266,9 @@ export function finishView (view) { li.innerHTML = html let disabled = 'disabled' if (typeof editor !== 'undefined' && window.havePermission()) { disabled = '' } - if (/^\s*\[[x ]\]\s*/.test(html)) { - li.innerHTML = html.replace(/^\s*\[ \]\s*/, ``) - .replace(/^\s*\[x\]\s*/, ``) + if (/^\s*\[[xX ]]\s*/.test(html)) { + li.innerHTML = html.replace(/^\s*\[ ]\s*/, ``) + .replace(/^\s*\[[xX]]\s*/, ``) if (li.tagName.toLowerCase() !== 'li') { li.parentElement.setAttribute('class', 'task-list-item') } else { @@ -705,11 +705,11 @@ $.fn.sortByDepth = function () { function toggleTodoEvent (e) { const startline = $(this).closest('li').attr('data-startline') - 1 const line = window.editor.getLine(startline) - const matches = line.match(/^[>\s-]*[-+*]\s\[([x ])\]/) + const matches = line.match(/^[>\s-]*(?:[-+*]|\d+[.)])\s\[([xX ])]/) if (matches && matches.length >= 2) { let checked = null - if (matches[1] === 'x') { checked = true } else if (matches[1] === ' ') { checked = false } - const replacements = matches[0].match(/(^[>\s-]*[-+*]\s\[)([x ])(\])/) + if (matches[1].toLowerCase() === 'x') { checked = true } else if (matches[1] === ' ') { checked = false } + const replacements = matches[0].match(/(^[>\s-]*(?:[-+*]|\d+[.)])\s\[)([xX ])(])/) window.editor.replaceRange(checked ? ' ' : 'x', { line: startline, ch: replacements[1].length -- cgit v1.2.3