feat: make checklists work with '-' instead of '*'
This commit is contained in:
parent
c0d744cfaa
commit
e17116dac1
1 changed files with 17 additions and 13 deletions
|
@ -304,8 +304,8 @@ export default {
|
||||||
},
|
},
|
||||||
findNthIndex(str, n) {
|
findNthIndex(str, n) {
|
||||||
|
|
||||||
const searchChecked = '* [x] '
|
const searchLength = 6
|
||||||
const searchUnchecked = '* [ ] '
|
const listPrefixes = ['*', '-']
|
||||||
|
|
||||||
let inChecked, inUnchecked, startIndex = 0
|
let inChecked, inUnchecked, startIndex = 0
|
||||||
// We're building an array with all checkboxes, checked or unchecked.
|
// We're building an array with all checkboxes, checked or unchecked.
|
||||||
|
@ -317,16 +317,18 @@ export default {
|
||||||
// Searching in two different loops for each search term since that is way easier and more predicatble
|
// Searching in two different loops for each search term since that is way easier and more predicatble
|
||||||
// More "intelligent" solutions sometimes don't have all values or duplicates.
|
// More "intelligent" solutions sometimes don't have all values or duplicates.
|
||||||
// Because we're sorting and removing duplicates of them, we can safely put everything in one giant array.
|
// Because we're sorting and removing duplicates of them, we can safely put everything in one giant array.
|
||||||
while ((inChecked = str.indexOf(searchChecked, startIndex)) > -1) {
|
listPrefixes.forEach(pref => {
|
||||||
checkboxes.push(inChecked)
|
while ((inChecked = str.indexOf(`${pref} [x]`, startIndex)) > -1) {
|
||||||
startIndex = startIndex + searchChecked.length
|
checkboxes.push(inChecked)
|
||||||
}
|
startIndex = startIndex + searchLength
|
||||||
|
}
|
||||||
|
|
||||||
startIndex = 0
|
startIndex = 0
|
||||||
while ((inUnchecked = str.indexOf(searchUnchecked, startIndex)) > -1) {
|
while ((inUnchecked = str.indexOf(`${pref} [ ]`, startIndex)) > -1) {
|
||||||
checkboxes.push(inUnchecked)
|
checkboxes.push(inUnchecked)
|
||||||
startIndex = startIndex + searchUnchecked.length
|
startIndex = startIndex + searchLength
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
checkboxes.sort((a, b) => a - b)
|
checkboxes.sort((a, b) => a - b)
|
||||||
checkboxes = checkboxes.filter((v, i, s) => s.indexOf(v) === i && v > -1)
|
checkboxes = checkboxes.filter((v, i, s) => s.indexOf(v) === i && v > -1)
|
||||||
|
@ -431,10 +433,12 @@ export default {
|
||||||
}
|
}
|
||||||
console.debug(index, this.text.substr(index, 9))
|
console.debug(index, this.text.substr(index, 9))
|
||||||
|
|
||||||
|
const listPrefix = this.text.substr(index, 1)
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
this.text = this.replaceAt(this.text, index, '* [x] ')
|
this.text = this.replaceAt(this.text, index, `${listPrefix} [x] `)
|
||||||
} else {
|
} else {
|
||||||
this.text = this.replaceAt(this.text, index, '* [ ] ')
|
this.text = this.replaceAt(this.text, index, `${listPrefix} [ ] `)
|
||||||
}
|
}
|
||||||
this.bubble()
|
this.bubble()
|
||||||
this.renderPreview()
|
this.renderPreview()
|
||||||
|
|
Loading…
Reference in a new issue