avoid selectNote loop, handle addAnnotation event

This commit is contained in:
j 2019-02-01 14:18:17 +05:30
parent 0dfc7db2bb
commit d5282b064a
1 changed files with 9 additions and 7 deletions

View File

@ -219,10 +219,9 @@ txtjs.noteExists = function(note) {
txtjs.onMessage = function(data, event) {
if (event == 'selectAnnotation') {
let selected = txtjs.getSelectedNote()
if (!selected || selected.id != data.id) {
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)
@ -446,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
@ -479,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) {
@ -501,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})
}
}