The Ace Editor
I embedded the Ace editor into my team’s current project - Visual Interpreter, a JavaScript interpreter tool for visualizing in-memory model values and scopes as well as doing inline code evaluation. This is the second post about using Ace for this project. The other two blogs are:
The Ace Editor and the DOM
I needed to figure out how to change the font color of text within for a given Range in my embedded Ace editor. More specifically, I wanted the text to dim or gray out (as if it was commented out code) in certain circumstances without actually commenting the code with
at the beginning of the line or with a block of text between 1
//
and 1
/*
. Basically, I was hoping to find a way to directly add a class to the actual text.1
*/
At the time of this post, Ace had no feature to manipulate font color so I came up with a hack to directly access the DOM and use jQuery to manipulate the font with css. My final code looked like this:
Note that in the code above I’m using
, a functions I built to convert a single character index into a row and column indices to make an Ace Range. You can read more about this in my previous blog post on Selection Highlighting with the Ace Editor.1
getRowColumnIndices
I then added the .ace_dimmer class to all the relevant classes in the theme-monokai.js file (since I was using the Monokai theme). This could probably be handled in a better way. Perhaps this is a case for using
.1
!important