Skip to content

Commit 021bac5

Browse files
authored
Merge pull request #2589 from arcturus140/master
fix 2530
2 parents 60c4cac + 480c056 commit 021bac5

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

browser/components/MarkdownEditor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class MarkdownEditor extends React.Component {
147147
e.preventDefault()
148148
e.stopPropagation()
149149
const idMatch = /checkbox-([0-9]+)/
150-
const checkedMatch = /\[x\]/i
151-
const uncheckedMatch = /\[ \]/
150+
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
151+
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
152152
if (idMatch.test(e.target.getAttribute('id'))) {
153153
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
154154
const lines = this.refs.code.value
@@ -157,10 +157,10 @@ class MarkdownEditor extends React.Component {
157157
const targetLine = lines[lineIndex]
158158

159159
if (targetLine.match(checkedMatch)) {
160-
lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]')
160+
lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]')
161161
}
162162
if (targetLine.match(uncheckedMatch)) {
163-
lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]')
163+
lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]')
164164
}
165165
this.refs.code.setValue(lines.join('\n'))
166166
}

browser/components/MarkdownSplitEditor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class MarkdownSplitEditor extends React.Component {
7878
e.preventDefault()
7979
e.stopPropagation()
8080
const idMatch = /checkbox-([0-9]+)/
81-
const checkedMatch = /\[x\]/i
82-
const uncheckedMatch = /\[ \]/
81+
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
82+
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
8383
if (idMatch.test(e.target.getAttribute('id'))) {
8484
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
8585
const lines = this.refs.code.value
@@ -88,10 +88,10 @@ class MarkdownSplitEditor extends React.Component {
8888
const targetLine = lines[lineIndex]
8989

9090
if (targetLine.match(checkedMatch)) {
91-
lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]')
91+
lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]')
9292
}
9393
if (targetLine.match(uncheckedMatch)) {
94-
lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]')
94+
lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]')
9595
}
9696
this.refs.code.setValue(lines.join('\n'))
9797
}

tests/lib/get-todo-status-test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ test('getTodoStatus should return a correct hash object', t => {
1717
['+ [ ] a\n+ [xtest] a\n', { total: 1, completed: 0 }],
1818
['+ [ ] a\n+ foo[x]bar a\n', { total: 1, completed: 0 }],
1919
['+ [ ] a\n+ foo[x] bar a\n', { total: 1, completed: 0 }],
20-
['+ [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }]
20+
['+ [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }],
21+
['* [ ] `- [ ] a`\n', { total: 1, completed: 0 }],
22+
['+ [ ] `- [ ] a`\n', { total: 1, completed: 0 }],
23+
['- [ ] `- [ ] a`\n', { total: 1, completed: 0 }],
24+
['- [ ] `- [x] a`\n', { total: 1, completed: 0 }],
25+
['- [ ] `- [X] a`\n', { total: 1, completed: 0 }],
26+
['- [x] `- [ ] a`\n', { total: 1, completed: 1 }],
27+
['- [X] `- [ ] a`\n', { total: 1, completed: 1 }],
28+
['- [x] `- [x] a`\n', { total: 1, completed: 1 }],
29+
['- [X] `- [X] a`\n', { total: 1, completed: 1 }],
30+
[' \t - [X] `- [X] a`\n', { total: 1, completed: 1 }],
31+
[' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }]
2132
]
2233

2334
testCases.forEach(testCase => {

0 commit comments

Comments
 (0)