Skip to content

Commit

Permalink
Added + as bullet, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
profi248 committed Mar 20, 2017
1 parent d07c62e commit c56d232
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class CodeEditor extends React.Component {
if (cm.somethingSelected()) cm.indentSelection('add')
else {
const tabs = cm.getOption('indentWithTabs')
if (line.trimLeft() === '- ' || line.trimLeft() === '* ') {
if (line.trimLeft() === '- ' || line.trimLeft() === '* ' || line.trimLeft() === '+ ') {
cm.execCommand('goLineStart')
if (tabs) {
cm.execCommand('insertTab')
Expand All @@ -85,18 +85,30 @@ export default class CodeEditor extends React.Component {
Enter: (cm) => {
const cursor = cm.getCursor()
const line = cm.getLine(cursor.line)
const dash = line.trim().startsWith('- ')
const numberedListRegex = /(\d+)\. .+/
let bulletType;
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)
if (line.trim().startsWith('- ') || line.trim().startsWith('* ') || match) {
if (bulletType !== 0 || match) {
cm.execCommand('newlineAndIndent')
const range = {line: cursor.line + 1, ch: cm.getLine(cursor.line + 1).length}
if (match) {
cm.replaceRange((parseInt(match[1]) + 1) + '. ', range)
} else if (dash) {
} else if (bulletType === 1) {
cm.replaceRange('- ', range)
} else {
} else if (bulletType === 2) {
cm.replaceRange('* ', range)
} else if (bulletType === 3) {
cm.replaceRange('+ ', range)
}
} else {
cm.execCommand('newlineAndIndent')
Expand Down

0 comments on commit c56d232

Please sign in to comment.