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

Smart numbered lists, too

Has auto increment, but no auto indent on tab, I don't know what to do
This commit is contained in:
kostaldavid8
2017-02-16 13:18:17 +01:00
parent 77eb19af40
commit d6171dc502

View File

@@ -86,10 +86,14 @@ export default class CodeEditor extends React.Component {
const cursor = cm.getCursor()
const line = cm.getLine(cursor.line)
const dash = line.trim().startsWith('- ')
if (line.trim().startsWith('- ') || line.trim().startsWith('* ')) {
const numberedListRegex = /(\d+)\. .+/
const match = line.trim().match(numberedListRegex)
if (line.trim().startsWith('- ') || line.trim().startsWith('* ') || match) {
cm.execCommand('newlineAndIndent')
const range = {line: cursor.line + 1, ch: cm.getLine(cursor.line + 1).length}
if (dash) {
if (match) {
cm.replaceRange((parseInt(match[1]) + 1) + '. ', range)
} else if (dash) {
cm.replaceRange('- ', range)
} else {
cm.replaceRange('* ', range)