From d6171dc5020984cc752bfb7fa8c6bfeaf16ef7b5 Mon Sep 17 00:00:00 2001 From: kostaldavid8 Date: Thu, 16 Feb 2017 13:18:17 +0100 Subject: [PATCH] Smart numbered lists, too Has auto increment, but no auto indent on tab, I don't know what to do --- browser/components/CodeEditor.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 03270de2..ad650ccf 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -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)