Skip to content

Commit

Permalink
#4199 - Jumping to the end of a long annotation sometimes does not work
Browse files Browse the repository at this point in the history
- Fix issue (hopefully)
- Also fix another occasional issue when keying through the ADEP
  • Loading branch information
reckart committed Sep 20, 2023
1 parent 8519b8e commit 014da5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export class ApacheAnnotatorVisualizer {
private showInlineLabels = false
private showEmptyHighlights = false

private removePingMarkers: (() => void)[] = []
private removePingMarkersTimeout: number | undefined = undefined
private removeTransientMarkers: (() => void)[] = []
private removeTransientMarkersTimeout: number | undefined = undefined

private alpha = '55'

constructor (element: Element, ajax: DiamAjax) {
Expand Down Expand Up @@ -110,6 +111,7 @@ export class ApacheAnnotatorVisualizer {
if (doc.spans) {
console.log(`Loaded ${doc.spans.size} span annotations`)
doc.spans.forEach(span => this.renderSpanAnnotation(doc, span))

this.removeSpuriousZeroWidthHighlights()
if (!this.showEmptyHighlights) {
this.removeWhitepaceOnlyHighlights()
Expand Down Expand Up @@ -159,7 +161,7 @@ export class ApacheAnnotatorVisualizer {

const vhl = this.root.ownerDocument.createElement('div')
vhl.classList.add('iaa-vertical-marker-focus')
vhl.style.top = `${top - scrollerContainerRect.top + this.root.scrollTop}px`
vhl.style.top = `${top - scrollerContainerRect.top + (this.root.scrollTop || 0)}px`
vhl.style.height = `${bottom - top}px`
this.root.appendChild(vhl)

Expand Down Expand Up @@ -206,8 +208,8 @@ export class ApacheAnnotatorVisualizer {
/**
* Some highliths may only contain whitepace. This method removes such highlights.
*/
private removeWhitepaceOnlyHighlights () {
this.getAllHighlights().forEach(e => {
private removeWhitepaceOnlyHighlights (selector: string = '.iaa-highlighted') {
this.root.querySelectorAll(selector).forEach(e => {
if (!e.classList.contains('iaa-zero-width') && !e.textContent?.trim()) {
e.after(...e.childNodes)
e.remove()
Expand Down Expand Up @@ -338,16 +340,21 @@ export class ApacheAnnotatorVisualizer {
const range = offsetToRange(this.root, args.offset, args.offset)
if (!range) return

window.clearTimeout(this.removePingMarkersTimeout)
this.removePingMarkers.forEach(remove => remove())
window.clearTimeout(this.removeTransientMarkersTimeout)
this.removeTransientMarkers.forEach(remove => remove())

const removeScrollMarker = highlightText(range, 'mark', { id: 'iaa-scroll-marker' })
this.removePingMarkers = []
this.removeTransientMarkers = [removeScrollMarker]
for (const pingOffset of args.pingRanges || []) {
const pingRange = offsetToRange(this.root, pingOffset[0], pingOffset[1])
if (!pingRange) continue
this.removePingMarkers.push(highlightText(pingRange, 'mark', { class: 'iaa-ping-marker' }))
this.removeTransientMarkers.push(highlightText(pingRange, 'mark', { class: 'iaa-ping-marker' }))
}

if (!this.showEmptyHighlights) {
this.removeWhitepaceOnlyHighlights('.iaa-ping-marker')
}

this.root.querySelectorAll('.iaa-ping-marker').forEach(e => {
if (!e.textContent) e.remove()
})
Expand All @@ -371,10 +378,9 @@ export class ApacheAnnotatorVisualizer {
scrollTarget.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' })
}

removeScrollMarker()
this.removePingMarkersTimeout = window.setTimeout(() => {
this.removePingMarkers.forEach(remove => remove())
console.log('ping removed')
this.removeTransientMarkersTimeout = window.setTimeout(() => {
this.removeTransientMarkers.forEach(remove => remove())
this.removeTransientMarkers = []
}, 2000)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ $(document).ready(function() {
// http://stackoverflow.com/questions/2335553/jquery-how-to-catch-enter-key-and-change-event-to-tab

function moveToNextInput(current) {
var inputs = $(current).parents("#annotationFeatureForm").eq(0).find(":input");
var idx = inputs.index(current);
let inputs = $(current).parents("#annotationFeatureForm").eq(0).find(":input");
let idx = inputs.index(current);
if (idx == inputs.length - 1) {
inputs[idx].blur();
} else {
inputs[idx + 1].focus(); // handles submit buttons
inputs[idx + 1].select();
let input = inputs[idx + 1];
if (input.focus) input.focus(); // handles submit buttons
if (input.select) input.select();
}
}

Expand Down

0 comments on commit 014da5b

Please sign in to comment.