1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Added + as bullet, bug fix

This commit is contained in:
kostaldavid8
2017-03-20 19:22:31 +01:00
parent d07c62e266
commit c56d232e58

View File

@@ -62,7 +62,7 @@ export default class CodeEditor extends React.Component {
if (cm.somethingSelected()) cm.indentSelection('add') if (cm.somethingSelected()) cm.indentSelection('add')
else { else {
const tabs = cm.getOption('indentWithTabs') const tabs = cm.getOption('indentWithTabs')
if (line.trimLeft() === '- ' || line.trimLeft() === '* ') { if (line.trimLeft() === '- ' || line.trimLeft() === '* ' || line.trimLeft() === '+ ') {
cm.execCommand('goLineStart') cm.execCommand('goLineStart')
if (tabs) { if (tabs) {
cm.execCommand('insertTab') cm.execCommand('insertTab')
@@ -85,18 +85,30 @@ export default class CodeEditor extends React.Component {
Enter: (cm) => { Enter: (cm) => {
const cursor = cm.getCursor() const cursor = cm.getCursor()
const line = cm.getLine(cursor.line) const line = cm.getLine(cursor.line)
const dash = line.trim().startsWith('- ') let bulletType;
const numberedListRegex = /(\d+)\. .+/ if (line.trim().startsWith('- ')) {
bulletType = 1 // dash
} else if (line.trim().startsWith('* ')) {
bulletType = 2 // star
} else if (line.trim().startsWith('+ ')) {
bulletType = 3 // plus
} else {
bulletType = 0 // not a bullet
}
console.log(bulletType);
const numberedListRegex = /^(\d+)\. .+/
const match = line.trim().match(numberedListRegex) const match = line.trim().match(numberedListRegex)
if (line.trim().startsWith('- ') || line.trim().startsWith('* ') || match) { if (bulletType !== 0 || match) {
cm.execCommand('newlineAndIndent') cm.execCommand('newlineAndIndent')
const range = {line: cursor.line + 1, ch: cm.getLine(cursor.line + 1).length} const range = {line: cursor.line + 1, ch: cm.getLine(cursor.line + 1).length}
if (match) { if (match) {
cm.replaceRange((parseInt(match[1]) + 1) + '. ', range) cm.replaceRange((parseInt(match[1]) + 1) + '. ', range)
} else if (dash) { } else if (bulletType === 1) {
cm.replaceRange('- ', range) cm.replaceRange('- ', range)
} else { } else if (bulletType === 2) {
cm.replaceRange('* ', range) cm.replaceRange('* ', range)
} else if (bulletType === 3) {
cm.replaceRange('+ ', range)
} }
} else { } else {
cm.execCommand('newlineAndIndent') cm.execCommand('newlineAndIndent')