mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 02:36:36 +00:00
Added the auto-updating numbered list to the middle of a list
This commit is contained in:
@@ -44,9 +44,46 @@
|
|||||||
? match[2].replace('x', ' ')
|
? match[2].replace('x', ' ')
|
||||||
: (parseInt(match[3], 10) + 1) + match[4]
|
: (parseInt(match[3], 10) + 1) + match[4]
|
||||||
replacements[i] = '\n' + indent + bullet + after
|
replacements[i] = '\n' + indent + bullet + after
|
||||||
|
|
||||||
|
if (bullet) incrementRemainingMarkdownListNumbers(cm, pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.replaceSelections(replacements)
|
cm.replaceSelections(replacements)
|
||||||
}
|
}
|
||||||
|
// Auto-updating Markdown list numbers when a new item is added to the
|
||||||
|
// middle of a list
|
||||||
|
function incrementRemainingMarkdownListNumbers(cm, pos) {
|
||||||
|
var startLine = pos.line, lookAhead = 0, skipCount = 0
|
||||||
|
var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1]
|
||||||
|
|
||||||
|
do {
|
||||||
|
lookAhead += 1
|
||||||
|
var nextLineNumber = startLine + lookAhead
|
||||||
|
var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine)
|
||||||
|
|
||||||
|
if (nextItem) {
|
||||||
|
var nextIndent = nextItem[1]
|
||||||
|
var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount)
|
||||||
|
var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber
|
||||||
|
|
||||||
|
if (startIndent === nextIndent && !isNaN(nextNumber)) {
|
||||||
|
if (newNumber === nextNumber) itemNumber = nextNumber + 1
|
||||||
|
if (newNumber > nextNumber) itemNumber = newNumber + 1
|
||||||
|
cm.replaceRange(
|
||||||
|
nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
|
||||||
|
{
|
||||||
|
line: nextLineNumber, ch: 0
|
||||||
|
}, {
|
||||||
|
line: nextLineNumber, ch: nextLine.length
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (startIndent.length > nextIndent.length) return
|
||||||
|
// This doesn't run if the next line immediatley indents, as it is
|
||||||
|
// not clear of the users intention (new indented item or same level)
|
||||||
|
if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return
|
||||||
|
skipCount += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (nextItem)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user