From 2a774d20f4652512d31f7e444445967ad9aa39dc Mon Sep 17 00:00:00 2001 From: Arcturus Date: Fri, 9 Nov 2018 12:21:00 +0000 Subject: [PATCH] fix issue 2530 --- browser/components/MarkdownEditor.js | 8 ++++---- browser/components/MarkdownSplitEditor.js | 10 +++++----- tests/lib/get-todo-status-test.js | 13 ++++++++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index 9c8a06d6..519e92f2 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -147,8 +147,8 @@ class MarkdownEditor extends React.Component { e.preventDefault() e.stopPropagation() const idMatch = /checkbox-([0-9]+)/ - const checkedMatch = /\[x\]/i - const uncheckedMatch = /\[ \]/ + const checkedMatch = /^\s*[\+\-\*] \[x\]/i + const uncheckedMatch = /^\s*[\+\-\*] \[ \]/ if (idMatch.test(e.target.getAttribute('id'))) { const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1 const lines = this.refs.code.value @@ -157,10 +157,10 @@ class MarkdownEditor extends React.Component { const targetLine = lines[lineIndex] if (targetLine.match(checkedMatch)) { - lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]') + lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]') } if (targetLine.match(uncheckedMatch)) { - lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]') + lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]') } this.refs.code.setValue(lines.join('\n')) } diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index ca2d3108..22ccca56 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -77,9 +77,9 @@ class MarkdownSplitEditor extends React.Component { handleCheckboxClick (e) { e.preventDefault() e.stopPropagation() - const idMatch = /checkbox-([0-9]+)/ - const checkedMatch = /\[x\]/i - const uncheckedMatch = /\[ \]/ + const idMatch = /checkbox-([0-9]+)/ + const checkedMatch = /^\s*[\+\-\*] \[x\]/i + const uncheckedMatch = /^\s*[\+\-\*] \[ \]/ if (idMatch.test(e.target.getAttribute('id'))) { const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1 const lines = this.refs.code.value @@ -88,10 +88,10 @@ class MarkdownSplitEditor extends React.Component { const targetLine = lines[lineIndex] if (targetLine.match(checkedMatch)) { - lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]') + lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]') } if (targetLine.match(uncheckedMatch)) { - lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]') + lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]') } this.refs.code.setValue(lines.join('\n')) } diff --git a/tests/lib/get-todo-status-test.js b/tests/lib/get-todo-status-test.js index ea07c03e..e00d7918 100644 --- a/tests/lib/get-todo-status-test.js +++ b/tests/lib/get-todo-status-test.js @@ -17,7 +17,18 @@ test('getTodoStatus should return a correct hash object', t => { ['+ [ ] a\n+ [xtest] a\n', { total: 1, completed: 0 }], ['+ [ ] a\n+ foo[x]bar a\n', { total: 1, completed: 0 }], ['+ [ ] a\n+ foo[x] bar a\n', { total: 1, completed: 0 }], - ['+ [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }] + ['+ [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }], + ['* [ ] `- [ ] a`\n', { total: 1, completed: 0 }], + ['+ [ ] `- [ ] a`\n', { total: 1, completed: 0 }], + ['- [ ] `- [ ] a`\n', { total: 1, completed: 0 }], + ['- [ ] `- [x] a`\n', { total: 1, completed: 0 }], + ['- [ ] `- [X] a`\n', { total: 1, completed: 0 }], + ['- [x] `- [ ] a`\n', { total: 1, completed: 1 }], + ['- [X] `- [ ] a`\n', { total: 1, completed: 1 }], + ['- [x] `- [x] a`\n', { total: 1, completed: 1 }], + ['- [X] `- [X] a`\n', { total: 1, completed: 1 }], + [' \t - [X] `- [X] a`\n', { total: 1, completed: 1 }], + [' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }], ] testCases.forEach(testCase => {