I've heard Ace provides functionality to get and patch diffs, but I searched through Ace's docs, tried googling but couldn't find how to do that.
Do Ace provide functionality to create and patch diffs of the document being editted?
From my research, I've figured that the way to do it is using google-diff-match-patch library (https://code.google.com/p/google-diff-match-patch/). But I'd prefer using Ace's builtin mechanism if it has one.
No Ace doesn't provide a functionality to patch diffs. You need to use diff-match-patch,
e.g to diff to values apply patch to ace document use
var Range = require("ace/range").Range;
var dmplib = require("diff_match_patch");
var dmp = new dmplib.diff_match_patch();
var diff = dmp.diff_main(oldValue, newValue, true);
var offset = 0;
diff.forEach(function(chunk) {
var op = chunk[0];
var text = chunk[1];
if (op === 0) {
offset += text.length;
} else if (op === -1) {
doc.remove(Range.fromPoints(
doc.indexToPosition(offset),
doc.indexToPosition(offset + text.length)
));
} else if (op === 1) {
doc.insert(doc.indexToPosition(offset), text);
offset += text.length;
}
});