Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created April 6, 2020 10:20
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/a07cf732e668cb3f806fd6e684f665d2 to your computer and use it in GitHub Desktop.
Save bjoerntx/a07cf732e668cb3f806fd6e684f665d2 to your computer and use it in GitHub Desktop.
async function addComment() {
var id = Math.random().toString(36).substring(2); // random id
var userName = await getUserNames();
// create comment object
var comment = {
comment: "",
author: userName,
timestamp: Date.now(),
id: id,
};
var range = await getSelectionRange();
TXTextControl.select(range.start, 0);
// insert start target
TXTextControl.documentTargets.add("txcs_" + id, dt => {
dt.setName(JSON.stringify(comment));
dt.setDeleteable(false);
TXTextControl.select(range.end, 0);
// insert end target
TXTextControl.documentTargets.add("txce_" + id, endTarget => {
_activeComment = id;
refreshComments();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment