mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add support to bold selected text via kb shortcut
to improve upon #301 ctrl + : to bold a single word under caret or bold selected text if some text is selected (highlighted) #463
This commit is contained in:
@@ -11,7 +11,7 @@ class MarkdownEditor extends React.Component {
|
|||||||
|
|
||||||
this.escapeFromEditor = ['Control', 'w']
|
this.escapeFromEditor = ['Control', 'w']
|
||||||
|
|
||||||
this.supportMdWordBold = ['Control', ':']
|
this.supportMdSelectionBold = ['Control', ':']
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
status: 'PREVIEW',
|
status: 'PREVIEW',
|
||||||
@@ -169,12 +169,14 @@ class MarkdownEditor extends React.Component {
|
|||||||
if (!this.state.isLocked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
|
if (!this.state.isLocked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
|
||||||
document.activeElement.blur()
|
document.activeElement.blur()
|
||||||
}
|
}
|
||||||
if (this.supportMdWordBold.every(isNoteHandlerKey)) {
|
if (this.supportMdSelectionBold.every(isNoteHandlerKey)) {
|
||||||
this.addMdBetweenWord('**')
|
this.addMdAroundWord('**')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addMdBetweenWord (mdElement) {
|
addMdAroundWord (mdElement) {
|
||||||
|
if (this.refs.code.editor.getSelection())
|
||||||
|
return this.addMdAroundSelection(mdElement)
|
||||||
const currentCaret = this.refs.code.editor.getCursor()
|
const currentCaret = this.refs.code.editor.getCursor()
|
||||||
const word = this.refs.code.editor.findWordAt(currentCaret)
|
const word = this.refs.code.editor.findWordAt(currentCaret)
|
||||||
const cmDoc = this.refs.code.editor.getDoc()
|
const cmDoc = this.refs.code.editor.getDoc()
|
||||||
@@ -182,6 +184,10 @@ class MarkdownEditor extends React.Component {
|
|||||||
cmDoc.replaceRange(mdElement, { line: word.head.line, ch: word.head.ch + mdElement.length })
|
cmDoc.replaceRange(mdElement, { line: word.head.line, ch: word.head.ch + mdElement.length })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addMdAroundSelection (mdElement) {
|
||||||
|
this.refs.code.editor.replaceSelection(`${mdElement}${this.refs.code.editor.getSelection()}${mdElement}`)
|
||||||
|
}
|
||||||
|
|
||||||
handleKeyUp (e) {
|
handleKeyUp (e) {
|
||||||
const keyPressed = Object.assign(this.state.keyPressed, {
|
const keyPressed = Object.assign(this.state.keyPressed, {
|
||||||
[e.key]: false
|
[e.key]: false
|
||||||
|
|||||||
Reference in New Issue
Block a user