diff options
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/extra.js | 12 | ||||
-rw-r--r-- | public/js/lib/editor/utils.js | 11 |
2 files changed, 13 insertions, 10 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*/, `<input type="checkbox" class="task-list-item-checkbox "${disabled}><label></label>`) - .replace(/^\s*\[x\]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`) + if (/^\s*\[[xX ]]\s*/.test(html)) { + li.innerHTML = html.replace(/^\s*\[ ]\s*/, `<input type="checkbox" class="task-list-item-checkbox" ${disabled}><label></label>`) + .replace(/^\s*\[[xX]]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`) 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 diff --git a/public/js/lib/editor/utils.js b/public/js/lib/editor/utils.js index 70428b28..3d799267 100644 --- a/public/js/lib/editor/utils.js +++ b/public/js/lib/editor/utils.js @@ -1,4 +1,5 @@ const wrapSymbols = ['*', '_', '~', '^', '+', '='] + export function wrapTextWith (editor, cm, symbol) { if (!cm.getSelection()) { return CodeMirror.Pass @@ -106,12 +107,14 @@ export function insertOnStartOfLines (cm, symbol) { for (let i = 0; i < ranges.length; i++) { const range = ranges[i] if (!range.empty()) { - const from = range.from() - const to = range.to() - let selection = cm.getRange({ line: from.line, ch: 0 }, to) + const cursorFrom = range.from() + const cursorTo = range.to() + const firstLineStart = { line: cursorFrom.line, ch: 0 } + const lastLineEnd = { line: cursorTo.line, ch: cm.getLine(cursorTo.line).length } + let selection = cm.getRange(firstLineStart, lastLineEnd) selection = selection.replace(/\n/g, '\n' + symbol) selection = symbol + selection - cm.replaceRange(selection, from, to) + cm.replaceRange(selection, firstLineStart, lastLineEnd) } else { cm.replaceRange(symbol, { line: cursor.line, ch: 0 }, { line: cursor.line, ch: 0 }) } |