From 646002bff708b99d69b347e2c3774bb01450ae26 Mon Sep 17 00:00:00 2001 From: Dave Brondsema Date: Thu, 10 Sep 2015 21:54:41 +0000 Subject: [PATCH] Don't increment both start and end points if they are the same object (e.g. no selection) --- src/js/simplemde.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js/simplemde.js b/src/js/simplemde.js index 5978bbe..cb639e5 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -399,7 +399,9 @@ function _replaceSelection(cm, active, start, end) { cm.replaceSelection(start + text + end); startPoint.ch += start.length; - endPoint.ch += start.length; + if(startPoint !== endPoint) { + endPoint.ch += start.length; + } } cm.setSelection(startPoint, endPoint); cm.focus(); @@ -552,10 +554,14 @@ function _toggleBlock(editor, type, start_chars, end_chars) { if(type == "bold" || type == "strikethrough") { startPoint.ch -= 2; - endPoint.ch -= 2; + if(startPoint !== endPoint) { + endPoint.ch -= 2; + } } else if(type == "italic") { startPoint.ch -= 1; - endPoint.ch -= 1; + if(startPoint !== endPoint) { + endPoint.ch -= 1; + } } } else { text = cm.getSelection();