From 49a4ec5e167670820dd65793cadec0c5677b0de0 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 22 Feb 2017 03:33:42 +0900 Subject: [PATCH] Enable CTRL + B in a word to make it bold --- browser/components/MarkdownEditor.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index 2172db99..aeed5e08 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -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