Compare commits

...

2 commits

Author SHA1 Message Date
rlx
a71ffdb82f merge 2019-02-01 12:43:19 +05:30
rlx
99b88de8c4 position: in,out 2019-02-01 12:40:45 +05:30

View file

@ -2,17 +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)
})
} else if (event == 'removeAnnotation') {
txtjs.selectNote(data.id)
txtjs.removeNote()
}
}) })
}) })
@ -134,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 = {
@ -180,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) {
@ -227,8 +217,18 @@ 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)
})
} else if (event == 'removeAnnotation') {
txtjs.selectNote(data.id)
txtjs.removeNote()
}
} }
txtjs.postMessage = function(action, data) { txtjs.postMessage = function(action, data) {
@ -256,7 +256,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']