diff --git a/txt.js/txt.js b/txt.js/txt.js index ee85393..e63fdd9 100644 --- a/txt.js/txt.js +++ b/txt.js/txt.js @@ -2,14 +2,7 @@ let txtjs = {} Ox.load({UI: {loadCSS: false}}, function() { Ox.$parent.bindMessage(function(data, event) { - if (event == 'selectAnnotation') { - txtjs.selectNote(data.id) - } else if (event == 'addAnnotations') { - data.annotations.forEach(function(note) { - txtjs.renderNote(note) - txtjs.notes.push(note) - }) - } + txtjs.onMessage(data, event) }) }) @@ -131,7 +124,7 @@ txtjs.getNoteFromSelection = function() { return } let position = txtjs.getPosition(range) - let pos = position.split(':').map(function(v) { + let pos = position.split(',').map(function(v) { return parseInt(v) }) let note = { @@ -177,7 +170,7 @@ txtjs.getPosition = function(range) { while (' \n'.includes(txtjs.text.substr(end - 1, 1))) { end-- } - return start + ':' + end + return start + ',' + end } txtjs.getRange = function(id, start, end) { @@ -224,8 +217,15 @@ txtjs.noteExists = function(note) { }) } -txtjs.onMessage = function(action, data) { - +txtjs.onMessage = function(data, event) { + if (event == 'selectAnnotation') { + txtjs.selectNote(data.id) + } else if (event == 'addAnnotations') { + data.annotations.forEach(function(note) { + txtjs.renderNote(note) + txtjs.notes.push(note) + }) + } } txtjs.postMessage = function(action, data) { @@ -253,7 +253,7 @@ txtjs.removeNote = function() { } txtjs.renderNote = function(note) { - let pos = note.position.split(':').map(function(v) { + let pos = note.position.split(',').map(function(v) { return parseInt(v) }) let ids = ['txt', 'txt-scroll']