Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created May 2, 2012 16:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assertchris/2577836 to your computer and use it in GitHub Desktop.
Save assertchris/2577836 to your computer and use it in GitHub Desktop.
Highlight lines in Ace (Editor)
###
CoffeeScript
marker = null;
require(["ace/range"], (range) ->
marker = editor.getSession().addMarker(new range.Range(7, 0, 7, 2000), "warning", "line", true);
)
setTimeout(->
editor.getSession().removeMarker(marker)
, 3000)
###
###
CSS
.warning
{
background: rgba(255, 50, 50, 0.1);
position: absolute;
width: 100% !important;
left: 0 !important;
}
###
@xavierholt
Copy link

Seven years old, but still useful!

A note to others using this as a reference: This puts the marker on top of the line, and uses transparency to achieve the highlighting effect. This will recolor the text slightly (and enough markers on the same line will obscure it completely). If you change the last argument to addMarker() (parameter name inFront) to false the marker will sit beneath the text and you can use an opaque background color.

@kargirwar
Copy link

position: absolute is the secret sauce here. Without that you will be left scratching your head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment