diff --git a/doc/api/editorInfo.md b/doc/api/editorInfo.md index 31361a750..5a1f8b160 100644 --- a/doc/api/editorInfo.md +++ b/doc/api/editorInfo.md @@ -37,10 +37,16 @@ Returns the `rep` object. ## editorInfo.ace_isCaret(?) ## editorInfo.ace_getLineAndCharForPoint(?) ## editorInfo.ace_performDocumentApplyAttributesToCharRange(?) -## editorInfo.ace_setAttributeOnSelection(?) +## editorInfo.ace_setAttributeOnSelection(attribute, enabled) +Sets an attribute on current range. +Example: `call.editorInfo.ace_setAttributeOnSelection("turkey::balls", true); // turkey is the attribute here, balls is the value +Notes: to remove the attribute pass enabled as false + ## editorInfo.ace_toggleAttributeOnSelection(?) -## editorInfo.ace_getAttributeOnSelection(attribute) +## editorInfo.ace_getAttributeOnSelection(attribute, prevChar) Returns a boolean if an attribute exists on a selected range. +prevChar value should be true if you want to get the previous Character attribute instead of the current selection for example +if the caret is at position 0,1 (after first character) it's probable you want the attributes on the character at 0,0 The attribute should be the string name of the attribute applied to the selection IE subscript Example usage: Apply the activeButton Class to a button if an attribute is on a highlighted/selected caret position or range. Example: `call.editorInfo.ace_getAttributeOnSelection("subscript");` // call here is the callstack from aceEditEvent. diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 0cfdec3fa..16b549a1a 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -449,6 +449,8 @@ function Ace2Inner(){ return oldEvent; } + if(!evt) var evt = null; + currentCallStack = { type: type, docTextChanged: false, @@ -2337,10 +2339,22 @@ function Ace2Inner(){ } editorInfo.ace_setAttributeOnSelection = setAttributeOnSelection; - - function getAttributeOnSelection(attributeName){ + // Get the the attribute on selection + // 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 withIt = Changeset.makeAttribsString('+', [ [attributeName, 'true'] ], rep.apool);