i'm trying to assign click event on highlighted keywords like this:
$('.ace-keyword').live('click', function(){
alert($(this));
});
but it's not working. Is it a bug or i just doing this wrong?
ace adds only dom nodes only for visible text
and whole dom is reconstructed every time user scrolls or types something
so using code from your example would be wasteful
also to changing parts of the dom have pointer-events: none
style applied to not break scrolling on safari
here's an example which highlights clicked token
var Range = require("ace/range").Range, markerId
var handler = function(e){
var editor = e.editor
console.log(e)
var pos = editor.getCursorPosition()
var token = editor.session.getTokenAt(pos.row, pos.column)
if (/\bkeyword\b/.test(token.type))
console.log(token.value, 'is a keyword')
// add highlight for the clicked token
var range = new Range(pos.row, token.start,
pos.row, token.start + token.value.length)
console.log(range)
editor.session.removeMarker(markerId)
markerId = editor.session.addMarker(range, 'ace_bracket red')
}
editor.on("click", handler)
thanks!
Most helpful comment
ace adds only dom nodes only for visible text
and whole dom is reconstructed every time user scrolls or types something
so using code from your example would be wasteful
also to changing parts of the dom have
pointer-events: none
style applied to not break scrolling on safarihere's an example which highlights clicked token