mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
fix issue 2530
This commit is contained in:
@@ -147,8 +147,8 @@ class MarkdownEditor extends React.Component {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
const idMatch = /checkbox-([0-9]+)/
|
const idMatch = /checkbox-([0-9]+)/
|
||||||
const checkedMatch = /\[x\]/i
|
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
|
||||||
const uncheckedMatch = /\[ \]/
|
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
|
||||||
if (idMatch.test(e.target.getAttribute('id'))) {
|
if (idMatch.test(e.target.getAttribute('id'))) {
|
||||||
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
|
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
|
||||||
const lines = this.refs.code.value
|
const lines = this.refs.code.value
|
||||||
@@ -157,10 +157,10 @@ class MarkdownEditor extends React.Component {
|
|||||||
const targetLine = lines[lineIndex]
|
const targetLine = lines[lineIndex]
|
||||||
|
|
||||||
if (targetLine.match(checkedMatch)) {
|
if (targetLine.match(checkedMatch)) {
|
||||||
lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]')
|
lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]')
|
||||||
}
|
}
|
||||||
if (targetLine.match(uncheckedMatch)) {
|
if (targetLine.match(uncheckedMatch)) {
|
||||||
lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]')
|
lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]')
|
||||||
}
|
}
|
||||||
this.refs.code.setValue(lines.join('\n'))
|
this.refs.code.setValue(lines.join('\n'))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
handleCheckboxClick (e) {
|
handleCheckboxClick (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
const idMatch = /checkbox-([0-9]+)/
|
const idMatch = /checkbox-([0-9]+)/
|
||||||
const checkedMatch = /\[x\]/i
|
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
|
||||||
const uncheckedMatch = /\[ \]/
|
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
|
||||||
if (idMatch.test(e.target.getAttribute('id'))) {
|
if (idMatch.test(e.target.getAttribute('id'))) {
|
||||||
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
|
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
|
||||||
const lines = this.refs.code.value
|
const lines = this.refs.code.value
|
||||||
@@ -88,10 +88,10 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
const targetLine = lines[lineIndex]
|
const targetLine = lines[lineIndex]
|
||||||
|
|
||||||
if (targetLine.match(checkedMatch)) {
|
if (targetLine.match(checkedMatch)) {
|
||||||
lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]')
|
lines[lineIndex] = targetLine.replace(checkedMatch, '- [ ]')
|
||||||
}
|
}
|
||||||
if (targetLine.match(uncheckedMatch)) {
|
if (targetLine.match(uncheckedMatch)) {
|
||||||
lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]')
|
lines[lineIndex] = targetLine.replace(uncheckedMatch, '- [x]')
|
||||||
}
|
}
|
||||||
this.refs.code.setValue(lines.join('\n'))
|
this.refs.code.setValue(lines.join('\n'))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,18 @@ test('getTodoStatus should return a correct hash object', t => {
|
|||||||
['+ [ ] a\n+ [xtest] a\n', { total: 1, completed: 0 }],
|
['+ [ ] 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+ 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 => {
|
testCases.forEach(testCase => {
|
||||||
|
|||||||
Reference in New Issue
Block a user