enter to add annotation
This commit is contained in:
parent
8ab9ac9588
commit
fedd0c7e80
4 changed files with 68 additions and 20 deletions
|
|
@ -44,12 +44,18 @@ window.addEventListener('keydown', function(event) {
|
|||
if (selected) {
|
||||
removeAnnotation(selected.dataset.id)
|
||||
}
|
||||
} else if (event.key == 'n') {
|
||||
} else if (event.key == 'n' || event.keyCode == 13) {
|
||||
var selected = document.querySelector('.oml-annotation.selected')
|
||||
if (!window.getSelection().isCollapsed) {
|
||||
if (selected) {
|
||||
deselectAllAnnotations()
|
||||
}
|
||||
var annot = getHighlight()
|
||||
renderAnnotation(annot)
|
||||
addAnnotation(annot)
|
||||
window.getSelection().removeAllRanges();
|
||||
} else if (selected) {
|
||||
console.log('editNote?', selected.dataset.id)
|
||||
}
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
|
@ -139,6 +145,7 @@ function selectAnnotation(id) {
|
|||
g.style.backgroundColor = 'blue'
|
||||
})
|
||||
}
|
||||
|
||||
function deselectAnnotation(id) {
|
||||
document.querySelectorAll('.oml-annotation.a' + id).forEach(function(g) {
|
||||
g.classList.remove('selected')
|
||||
|
|
@ -146,6 +153,20 @@ function deselectAnnotation(id) {
|
|||
})
|
||||
}
|
||||
|
||||
function deselectAllAnnotations() {
|
||||
var ids = []
|
||||
document.querySelectorAll('.oml-annotation.selected').forEach(function(g) {
|
||||
g.classList.remove('selected')
|
||||
g.style.backgroundColor = 'yellow'
|
||||
var id = $(g).parents('.oml-annotation').data('id')
|
||||
console.log('deselect', g, id)
|
||||
if (!Ox.contains(ids, id)) {
|
||||
ids.push(id)
|
||||
Ox.$parent.postMessage('deselectAnnotation', {id: id})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function removeAnnotation(id) {
|
||||
document.querySelectorAll('.oml-annotation.a' + id).forEach(function(a) {
|
||||
a.remove()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue