mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
Smart bullets
When you hit enter on a line with a bullet, you get a new one on the new line. Also when you hit tab after a bullet, it automatically indents. It makes typing with bullets much more pleasant.
This commit is contained in:
@@ -57,17 +57,35 @@ export default class CodeEditor extends React.Component {
|
|||||||
inputStyle: 'textarea',
|
inputStyle: 'textarea',
|
||||||
extraKeys: {
|
extraKeys: {
|
||||||
Tab: function (cm) {
|
Tab: function (cm) {
|
||||||
|
let cursor = cm.getCursor()
|
||||||
|
let line = cm.getLine(cursor.line)
|
||||||
if (cm.somethingSelected()) cm.indentSelection('add')
|
if (cm.somethingSelected()) cm.indentSelection('add')
|
||||||
else {
|
else {
|
||||||
if (cm.getOption('indentWithTabs')) {
|
let tabs = cm.getOption('indentWithTabs')
|
||||||
cm.execCommand('insertTab')
|
if (line.trimLeft() === '- ' || line.trimLeft() === '* ') {
|
||||||
|
cm.execCommand('goLineStart')
|
||||||
|
if (tabs) cm.execCommand('insertTab'); else cm.execCommand('insertSoftTab')
|
||||||
|
cm.execCommand('goLineEnd')
|
||||||
} else {
|
} else {
|
||||||
cm.execCommand('insertSoftTab')
|
if (tabs) cm.execCommand('insertTab'); else cm.execCommand('insertSoftTab')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Cmd-T': function (cm) {
|
'Cmd-T': function (cm) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
},
|
||||||
|
Enter: function (cm) {
|
||||||
|
let cursor = cm.getCursor()
|
||||||
|
let line = cm.getLine(cursor.line)
|
||||||
|
let dash = line.trim().startsWith('- ')
|
||||||
|
if ((line.trim().startsWith('- ') || line.trim().startsWith('* '))) {
|
||||||
|
cm.execCommand('newlineAndIndent')
|
||||||
|
let range = {line: cursor.line + 1, ch: cm.getLine(cursor.line + 1).length}
|
||||||
|
console.log(range)
|
||||||
|
if (dash) cm.replaceRange('- ', range); else cm.replaceRange('* ', range)
|
||||||
|
} else {
|
||||||
|
cm.execCommand('newlineAndIndent')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user