I am trying to figure out what characters the user changed in a string. Fortunately, I can only imagine one subsequent block of changes.
I was not even able to find the place where the area was changed:
var originalVal, val;
var original = [0,0];
var new_rang = [0,0];
var ol = originalVal.length;
var nl = val.length;
for(var i=0; ; i++) {
if((i>=ol||i>=nl) || originalVal[i]!=val[i]) {
original[0] = new_rang[0] = i;
original[1] = new_rang[1] = i;
break;
}
}
This completely breaks if a string of identical characters and the user deletes one of them:
mmmmx
mMDEL> MMX
TTT x
Script will say that the change occurred at 4, where it xmoved. But in fact it is not even possible to say which has been deleted m .
However, I can tell where the cursor position was at the beginning and where it is at the end. This way, it looks more promising, but I still don't know what to do:
mm | Mmx
m > | MMX
| MMX
, m . , .