Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created May 12, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/880853dc9c084cfc544da378efdb7c0c to your computer and use it in GitHub Desktop.
Save bjoerntx/880853dc9c084cfc544da378efdb7c0c to your computer and use it in GitHub Desktop.
// connect to signalr hub
_connection = new signalR.HubConnectionBuilder().withUrl("/collabHub").build();
_connection.start();
_connection.on("ReceiveRegionSync", async function (syncRegion) {
// set flag to avoid infinite loops
_updating = true;
TXTextControl.editableRegions.forEach(function (er) {
// find editable region by id
er.getID(function (id) {
if (syncRegion.regionId == id) {
er.getStart(function (start) {
er.getLength(function (length) {
TXTextControl.inputPosition.getTextPosition(function (sp) {
// select editable region
var sel = TXTextControl.selection;
var bounds = { "start": start - 1, "length": length };
sel.setBounds(bounds);
//sel = TXTextControl.selection;
// load synchronized content
sel.load(TXTextControl.StreamType.InternalUnicodeFormat,
syncRegion.document);
// reset input position
var bounds = { "start": sp, "length": 0 };
sel.setBounds(bounds);
// reset flags
setTimeout(function () {
_updating = false;
_dirtyFlag = false;
}, 100);
});
});
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment