position: in,out

This commit is contained in:
rlx 2019-02-01 12:40:45 +05:30
parent e1937f3c7c
commit 99b88de8c4

View file

@ -2,14 +2,7 @@ let txtjs = {}
Ox.load({UI: {loadCSS: false}}, function() { Ox.load({UI: {loadCSS: false}}, function() {
Ox.$parent.bindMessage(function(data, event) { Ox.$parent.bindMessage(function(data, event) {
if (event == 'selectAnnotation') { txtjs.onMessage(data, event)
txtjs.selectNote(data.id)
} else if (event == 'addAnnotations') {
data.annotations.forEach(function(note) {
txtjs.renderNote(note)
txtjs.notes.push(note)
})
}
}) })
}) })
@ -131,7 +124,7 @@ txtjs.getNoteFromSelection = function() {
return return
} }
let position = txtjs.getPosition(range) let position = txtjs.getPosition(range)
let pos = position.split(':').map(function(v) { let pos = position.split(',').map(function(v) {
return parseInt(v) return parseInt(v)
}) })
let note = { let note = {
@ -177,7 +170,7 @@ txtjs.getPosition = function(range) {
while (' \n'.includes(txtjs.text.substr(end - 1, 1))) { while (' \n'.includes(txtjs.text.substr(end - 1, 1))) {
end-- end--
} }
return start + ':' + end return start + ',' + end
} }
txtjs.getRange = function(id, 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) { txtjs.postMessage = function(action, data) {
@ -253,7 +253,7 @@ txtjs.removeNote = function() {
} }
txtjs.renderNote = function(note) { txtjs.renderNote = function(note) {
let pos = note.position.split(':').map(function(v) { let pos = note.position.split(',').map(function(v) {
return parseInt(v) return parseInt(v)
}) })
let ids = ['txt', 'txt-scroll'] let ids = ['txt', 'txt-scroll']