-
-
Save StreetStrider/53557752391e57102a1031f2ba3164de to your computer and use it in GitHub Desktop.
quill diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findDiff() { | |
| var oldContent = quill_old.getContents(); | |
| var newContent = quill_new.getContents(); | |
| var diff = oldContent.diff(newContent); | |
| // console.log('old', oldContent); | |
| // console.log('new', newContent); | |
| for (var i = 0; i < diff.ops.length; i++) { | |
| var op = diff.ops[i]; | |
| // if the change was an insertion | |
| if (op.hasOwnProperty('insert')) { | |
| // color it green | |
| op.attributes = { | |
| background: "#cce8cc", | |
| color: "#003700" | |
| }; | |
| } | |
| // if the change was a deletion | |
| if (op.hasOwnProperty('delete')) { | |
| // keep the text | |
| op.retain = op.delete; | |
| delete op.delete; | |
| // but color it red and struckthrough | |
| op.attributes = { | |
| background: "#e8cccc", | |
| color: "#370000", | |
| strike: true | |
| }; | |
| } | |
| } | |
| // console.log('diff', diff); | |
| var adjusted = oldContent.compose(diff); | |
| // console.log('adjusted', adjusted); | |
| // profit! | |
| quill_diff.setContents(adjusted); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment