diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-28 21:24:11 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-28 21:24:11 +0100 |
commit | 4eedb599d8de5559daa4678c7520bb36968e767e (patch) | |
tree | 43830f8cf5c880d8be76b8f98bb2f73d78e38c78 /html | |
parent | a69b1d0c580bc779740ef79a7d16b69229896785 (diff) |
Server to client: diffs
Diffstat (limited to 'html')
-rw-r--r-- | html/whiteboard.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/html/whiteboard.js b/html/whiteboard.js index 58023fe..3e09621 100644 --- a/html/whiteboard.js +++ b/html/whiteboard.js @@ -48,6 +48,26 @@ function on_getfile(data, rev, pos) textAreaSetPos("board", pos); } +function on_getdiff(diff, rev) +{ + if (rev != revision + 1) + alert("Revision skipped: " + rev + " after " + revision); + + var board = document.getElementById("board"); + + var old_version_ptr = allocateUTF8(board.value); + var diff_ptr = allocateUTF8(new XMLSerializer().serializeToString(diff)); + var new_version_ptr = Module._diff_apply(old_version_ptr, diff_ptr); + var data = UTF8ToString(new_version_ptr); + board.value = data; + _free(old_version_ptr); + _free(new_version_ptr); + _free(diff_ptr); + + revision = rev; + baseline = data; +} + function on_getpos(pos) { textAreaSetPos("board", pos); @@ -88,6 +108,9 @@ function on_message(e) { on_getfile(xmlDocument.getElementsByTagName("data")[0].textContent, parseInt(xmlDocument.getElementsByTagName("revision")[0].textContent), parseInt(xmlDocument.getElementsByTagName("pos")[0].textContent)); + } else if (type == "getdiff") { + on_getdiff(xmlDocument.getElementsByTagName("diff")[0], + parseInt(xmlDocument.getElementsByTagName("revision")[0].textContent)); } else if (type == "getpos") { on_getpos(parseInt(xmlDocument.getElementsByTagName("pos")[0].textContent)); } else if (type == "modify") { @@ -216,10 +239,6 @@ function on_input() idElement.appendChild(document.createTextNode(get_id())); requestElement.appendChild(idElement); - var dataElement = xmlDocument.createElement("data"); - dataElement.appendChild(document.createTextNode(document.getElementById("board").value)); - requestElement.appendChild(dataElement); - baseline_candidate = document.getElementById("board").value; var revisionElement = xmlDocument.createElement("baserev"); |