mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Enable CTRL + B in a word to make it bold
This commit is contained in:
@@ -11,7 +11,9 @@ class MarkdownEditor extends React.Component {
|
||||
|
||||
this.escapeFromEditor = ['Control', 'w']
|
||||
|
||||
this.supportBold = ['Control', 'b']
|
||||
this.supportMdBold = ['Control', 'b']
|
||||
|
||||
this.supportMdWordBold = ['Control', ':']
|
||||
|
||||
this.state = {
|
||||
status: 'PREVIEW',
|
||||
@@ -169,9 +171,12 @@ class MarkdownEditor extends React.Component {
|
||||
if (!this.state.isLocked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
|
||||
document.activeElement.blur()
|
||||
}
|
||||
if (this.supportBold.every(isNoteHandlerKey)) {
|
||||
if (this.supportMdBold.every(isNoteHandlerKey)) {
|
||||
this.addMdAndMoveCaretToCenter('****')
|
||||
}
|
||||
if (this.supportMdWordBold.every(isNoteHandlerKey)) {
|
||||
this.addMdBetweenWord('**')
|
||||
}
|
||||
}
|
||||
|
||||
addMdAndMoveCaretToCenter (md) {
|
||||
@@ -181,6 +186,14 @@ class MarkdownEditor extends React.Component {
|
||||
this.refs.code.editor.setCursor({line: currentCaret.line, ch: currentCaret.ch + md.length/2})
|
||||
}
|
||||
|
||||
addMdBetweenWord (md) {
|
||||
const currentCaret = this.refs.code.editor.getCursor()
|
||||
const word = this.refs.code.editor.findWordAt(currentCaret)
|
||||
const cmDoc = this.refs.code.editor.getDoc()
|
||||
cmDoc.replaceRange(md, word.anchor)
|
||||
cmDoc.replaceRange(md, { line: word.head.line, ch: word.head.ch + md.length })
|
||||
}
|
||||
|
||||
handleKeyUp (e) {
|
||||
const keyPressed = Object.assign(this.state.keyPressed, {
|
||||
[e.key]: false
|
||||
|
||||
Reference in New Issue
Block a user