avoid selectNote loop, handle addAnnotation event
This commit is contained in:
parent
0dfc7db2bb
commit
d5282b064a
1 changed files with 9 additions and 7 deletions
|
@ -219,10 +219,9 @@ txtjs.noteExists = function(note) {
|
||||||
|
|
||||||
txtjs.onMessage = function(data, event) {
|
txtjs.onMessage = function(data, event) {
|
||||||
if (event == 'selectAnnotation') {
|
if (event == 'selectAnnotation') {
|
||||||
let selected = txtjs.getSelectedNote()
|
txtjs.selectNote(data.id, false)
|
||||||
if (!selected || selected.id != data.id) {
|
} else if (event == 'addAnnotation') {
|
||||||
txtjs.selectNote(data.id)
|
txtjs.addNoteFromSelection()
|
||||||
}
|
|
||||||
} else if (event == 'addAnnotations') {
|
} else if (event == 'addAnnotations') {
|
||||||
data.annotations.forEach(function(note) {
|
data.annotations.forEach(function(note) {
|
||||||
txtjs.renderNote(note)
|
txtjs.renderNote(note)
|
||||||
|
@ -446,8 +445,9 @@ txtjs.renderText = function(text) {
|
||||||
let note = txtjs.getNoteFromSelection()
|
let note = txtjs.getNoteFromSelection()
|
||||||
if (!note || txtjs.noteExists(note)) {
|
if (!note || txtjs.noteExists(note)) {
|
||||||
txtjs.postMessage('selectText', null)
|
txtjs.postMessage('selectText', null)
|
||||||
|
} else {
|
||||||
|
txtjs.postMessage('selectText', note)
|
||||||
}
|
}
|
||||||
txtjs.postMessage('selectText', note)
|
|
||||||
}
|
}
|
||||||
function onResize() {
|
function onResize() {
|
||||||
factor = scrollTextElement.clientHeight / textElement.clientHeight
|
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(ids[Ox.mod(ids.indexOf(id) + direction, ids.length)])
|
||||||
}
|
}
|
||||||
|
|
||||||
txtjs.selectNote = function(id) {
|
txtjs.selectNote = function(id, trigger) {
|
||||||
let selected = txtjs.getSelectedNote()
|
let selected = txtjs.getSelectedNote()
|
||||||
if (selected) {
|
if (selected) {
|
||||||
selected.elements.forEach(function(element) {
|
selected.elements.forEach(function(element) {
|
||||||
|
@ -501,5 +501,7 @@ txtjs.selectNote = function(id) {
|
||||||
// elements[0].scrollIntoView()
|
// elements[0].scrollIntoView()
|
||||||
// window.scrollTo(0, elements[0].offsetTop)
|
// window.scrollTo(0, elements[0].offsetTop)
|
||||||
}
|
}
|
||||||
txtjs.postMessage('selectNote', {id: id})
|
if (trigger !== false) {
|
||||||
|
txtjs.postMessage('selectNote', {id: id})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue