diff --git a/README.md b/README.md index eb635e0..d871af3 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,4 @@ The name of the buttons are as follows - Ordered List = cmdList0 - Code = cmdCode - Quote = cmdQuote +- Equation = cmdEquation diff --git a/lib/codemwnci/bootstrap-markdown.js b/lib/codemwnci/bootstrap-markdown.js index 64fe437..6b6d392 100755 --- a/lib/codemwnci/bootstrap-markdown.js +++ b/lib/codemwnci/bootstrap-markdown.js @@ -1228,6 +1228,38 @@ } } + // Set the cursor + e.setSelection(cursor,cursor+chunk.length) + } + }, + { + name: 'cmdEquation', + hotkey: 'Ctrl+E', + title: 'Equation', + icon: { glyph: 'glyphicon glyphicon-superscript', fa: 'fa fa-superscript', 'fa-3': 'icon-superscript' }, + callback: function(e) { + + // Give/remove ** surround the selection + var chunk, cursor, selected = e.getSelection(), content = e.getContent() + + if (selected.length == 0) { + // Give extra word + chunk = e.__localize('LaTeX equation here') + } else { + chunk = selected.text + } + + // transform selection and set the cursor into chunked text + if (content.substr(selected.start-1,1) == '\\\\[' + && content.substr(selected.end,1) == '\\\\]' ) { + e.setSelection(selected.start+1,selected.end+1) + e.replaceSelection(chunk) + cursor = selected.start-1 + } else { + e.replaceSelection('\\\\['+chunk+'\\\\]') + cursor = selected.start+3 + } + // Set the cursor e.setSelection(cursor,cursor+chunk.length) }