| 912 | } |
| 913 | |
| 914 | function toggleTodoEvent (e) { |
| 915 | const startline = $(this).closest('li').attr('data-startline') - 1 |
| 916 | const line = window.editor.getLine(startline) |
| 917 | const matches = line.match(/^[>\s-]*[-+*]\s\[([x ])\]/) |
| 918 | if (matches && matches.length >= 2) { |
| 919 | let checked = null |
| 920 | if (matches[1] === 'x') { checked = true } else if (matches[1] === ' ') { checked = false } |
| 921 | const replacements = matches[0].match(/(^[>\s-]*[-+*]\s\[)([x ])(\])/) |
| 922 | window.editor.replaceRange(checked ? ' ' : 'x', { |
| 923 | line: startline, |
| 924 | ch: replacements[1].length |
| 925 | }, { |
| 926 | line: startline, |
| 927 | ch: replacements[1].length + 1 |
| 928 | }, '+input') |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | // remove hash |
| 933 | function removeHash () { |