1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-12 17:26:17 +00:00

Merge pull request #2589 from arcturus140/master

fix 2530
This commit is contained in:
Junyoung Choi (Sai)
2018-11-13 00:29:27 +09:00
committed by GitHub
3 changed files with 20 additions and 9 deletions

View File

@@ -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'))
}

View File

@@ -78,8 +78,8 @@ class MarkdownSplitEditor 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
@@ -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'))
}

View File

@@ -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 => {