Compare commits

...

2 Commits

Author SHA1 Message Date
j d5282b064a avoid selectNote loop, handle addAnnotation event 2019-02-01 14:18:17 +05:30
j 0dfc7db2bb avoid select loop 2019-02-01 14:02:10 +05:30
1 changed files with 9 additions and 4 deletions

View File

@ -219,7 +219,9 @@ txtjs.noteExists = function(note) {
txtjs.onMessage = function(data, event) {
if (event == 'selectAnnotation') {
txtjs.selectNote(data.id)
txtjs.selectNote(data.id, false)
} else if (event == 'addAnnotation') {
txtjs.addNoteFromSelection()
} else if (event == 'addAnnotations') {
data.annotations.forEach(function(note) {
txtjs.renderNote(note)
@ -443,8 +445,9 @@ txtjs.renderText = function(text) {
let note = txtjs.getNoteFromSelection()
if (!note || txtjs.noteExists(note)) {
txtjs.postMessage('selectText', null)
} else {
txtjs.postMessage('selectText', note)
}
txtjs.postMessage('selectText', note)
}
function onResize() {
factor = scrollTextElement.clientHeight / textElement.clientHeight
@ -476,7 +479,7 @@ txtjs.selectNextNote = function(direction) {
txtjs.selectNote(ids[Ox.mod(ids.indexOf(id) + direction, ids.length)])
}
txtjs.selectNote = function(id) {
txtjs.selectNote = function(id, trigger) {
let selected = txtjs.getSelectedNote()
if (selected) {
selected.elements.forEach(function(element) {
@ -498,5 +501,7 @@ txtjs.selectNote = function(id) {
// elements[0].scrollIntoView()
// window.scrollTo(0, elements[0].offsetTop)
}
txtjs.postMessage('selectNote', {id: id})
if (trigger !== false) {
txtjs.postMessage('selectNote', {id: id})
}
}