Ok, I need to have the ability to import parts of another page to an active pad using the HTTP API. I know that copy and paste works in the UI, but I need this to be done behind the scenes.
I've started with the appendText since it would be easiest to get working, and everything I need right now is text based.
So I mirrored the existing setText function of API.js and modified the APIHandler.js and got the new API calling correctly from the C# connector. I am able to get it to place the text at the end of the pad, but it kills the other editors (read other users) cursor placement and resets all the Authorship highlights. The users cursor is placed at the head of the pad after the update. It also resets all the formatting, but this is expected as I am using the text of the pad in the append.
I think I need to take the inbound text and create a patch that would be placed in the normal queue to be updated by all the clients, but I'm not sure how to do this. Not asking for someone to do this for me, just looking for a little pointer to help me along in this.
Here is the method that I was using.
exports.appendText = function(padID, text, callback)
{
//text is required
if(typeof text != "string")
{
callback(new customError("text is no string","apierror"));
return;
}
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
var curText = pad.text();
var finalText = curText + "\n" + text;
//set the text
pad.setText(finalText);
//update the clients on the pad
padMessageHandler.updatePadClients(pad, callback);
});
}
As you can see, it's identical to the way that setText works but it gets the current text of the pad, adds a line break and then the inbound text, and sets the pad text to the new value. It then tells the clients to update. I really think that it needs to create a diff of the existing text and the text with the appended text and then place that diff in the timeline to be updated by any active clients.
I also need to do this as HTML. I don't think that it will be difficult for me to do this once I get this working correctly, but if anyone can think of any pitfalls please let me know.
Thank you,
Dusty