I am looking for a way to detect in which block my change occurred.
I'm writing a small markdown parser and want a simple UI, in order to keep positions and performance I only want the live preview to update the part I'm actually changing. For this to work I need to know which part in the ace editor I'm modifying.
When I use the onchange
event the event data neatly specifies where my change occurred, which line and position. Before I start writing code which searches up and down for linebreaks I wanted to ask if there is a default way in the API to return which block changed.
You'll get something like this:
fs.readFile(__dirname + '/example.md', 'utf8', function(err, text) {
session = ace.createEditSession(text);
session.on('change', function(e, f) {
// getChangedParagraph does not exist and needs to return the
// actual block which changed.
var changedText = getChangedParagraph();
parseTheText(changedText);
});
editor.setSession(session);
});
There is no concept of blocks in ace. ace change events give line and column of change, You need to keep track of positions in the parser