diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index b559d9e3f..815d069d2 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -187,6 +187,17 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ getAttributeOnSelection: function(attributeName, prevChar){ var rep = this.rep; if (!(rep.selStart && rep.selEnd)) return + // If we're looking for the caret attribute not the selection + // has the user already got a selection or is this purely a caret location? + var isNotSelection = (rep.selStart[0] == rep.selEnd[0] && rep.selEnd[1] === rep.selStart[1]); + if(isNotSelection){ + if(prevChar){ + // If it's not the start of the line + if(rep.selStart[1] !== 0){ + rep.selStart[1]--; + } + } + } var withIt = Changeset.makeAttribsString('+', [ [attributeName, 'true'] diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index f7843a57f..5c8427463 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -2341,15 +2341,13 @@ function Ace2Inner(){ // prevChar tells the function if it needs to look at the previous character function getAttributeOnSelection(attributeName, prevChar){ if (!(rep.selStart && rep.selEnd)) return - - // If we're looking for the caret attribute not the selection - if(prevChar){ - // If it's not the start of the line - if(rep.selStart[1] !== 0){ - rep.selStart[1]--; - }else{ - // It's the start of the line so look at the first character - rep.selEnd[1]++; + var isNotSelection = (rep.selStart[0] == rep.selEnd[0] && rep.selEnd[1] === rep.selStart[1]); + if(isNotSelection){ + if(prevChar){ + // If it's not the start of the line + if(rep.selStart[1] !== 0){ + rep.selStart[1]--; + } } }