Skip to content

Commit bcb5100

Browse files
committed
annotator line parsing hotfix
1 parent 4ae0870 commit bcb5100

1 file changed

Lines changed: 51 additions & 44 deletions

File tree

components/annotorious-annotator/line-parser.js

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ class AnnotoriousAnnotator extends HTMLElement {
661661
if (_this.#isDrawing) _this.#annotoriousInstance.cancelSelected()
662662
_this.#annotoriousInstance.updateAnnotation(annotation)
663663
_this.#resolvedAnnotationPage.$isDirty = true
664-
_this.applyCursorBehavior()
665664
})
666665

667666
/**
@@ -673,7 +672,6 @@ class AnnotoriousAnnotator extends HTMLElement {
673672
// console.log("UPDATE ANNOTATION")
674673
_this.#annotoriousInstance.updateAnnotation(annotation)
675674
_this.#resolvedAnnotationPage.$isDirty = true
676-
_this.applyCursorBehavior()
677675
})
678676

679677
/**
@@ -1105,10 +1103,11 @@ class AnnotoriousAnnotator extends HTMLElement {
11051103
// Apply cursor behavior if an annotation is already selected
11061104
if (this.#annotoriousInstance.getSelected().length) {
11071105
this.applyCursorBehavior()
1108-
} else {
1109-
// Don't strictly HAVE to cancel, but it helps control the cursor.
1110-
this.#annotoriousInstance.cancelSelected()
1111-
}
1106+
}
1107+
// else {
1108+
// // Don't strictly HAVE to cancel, but it helps control the cursor.
1109+
// this.#annotoriousInstance.cancelSelected()
1110+
// }
11121111
}
11131112
}
11141113

@@ -1192,7 +1191,6 @@ class AnnotoriousAnnotator extends HTMLElement {
11921191

11931192
/**
11941193
* Activate Annotorious annotation chopping mode.
1195-
* Clicking on an existing annotation will prompt the user about deleting the annotation.
11961194
*/
11971195
startLineEditing(toast_it = true) {
11981196
this.stopDrawing(false)
@@ -1216,7 +1214,6 @@ class AnnotoriousAnnotator extends HTMLElement {
12161214

12171215
/**
12181216
* Activate Annotorious annotation chopping mode.
1219-
* Clicking on an existing annotation will prompt the user about deleting the annotation.
12201217
*/
12211218
stopLineEditing(toast_it = true) {
12221219
this.#isLineEditing = false
@@ -1441,36 +1438,19 @@ class AnnotoriousAnnotator extends HTMLElement {
14411438
*/
14421439
applyCursorBehavior() {
14431440
const elem = this.#annotoriousInstance.viewer.element.querySelector(".a9s-annotation.selected")
1444-
if (!elem) return
1441+
if (!elem || elem.getAttribute("behavior-registered") === "true") return
1442+
elem.setAttribute("behavior-registered", "true")
14451443
const cursorHandleElem = this.#annotoriousInstance.viewer.element.querySelector(".a9s-shape-handle")
14461444
const ruler = this.shadowRoot.getElementById("ruler")
14471445
const _this = this
1446+
let mouseStart
1447+
let mouseFinish
14481448

1449-
// Cursor support for editing options, applies when an Annotation is clicked and selected.
1450-
if (this.#isLineEditing) {
1451-
if (this.#editType === "add") {
1452-
elem.style.cursor = "crosshair"
1453-
cursorHandleElem.style.cursor = "crosshair"
1454-
ruler.style.display = "block"
1455-
} else if (this.#editType === "merge") {
1456-
elem.style.cursor = "cell"
1457-
cursorHandleElem.style.cursor = "cell"
1458-
} else {
1459-
elem.style.cursor = "move"
1460-
cursorHandleElem.style.cursor = "move"
1461-
}
1462-
} else {
1463-
elem.style.cursor = "move"
1464-
cursorHandleElem.style.cursor = "move"
1449+
function setMouseStart(e) {
1450+
mouseStart = [e.pageX, e.pageY]
14651451
}
14661452

1467-
// Variables for tracking mouse position during click vs drag detection
1468-
// Declared here so they're captured in the event listener closures below
1469-
let mouseStart = 0
1470-
let mouseFinish = 0
1471-
1472-
// Further cursor support when user changes edit options while an Annotation is selected.
1473-
elem.addEventListener('mouseenter', function(e) {
1453+
function applyMouseEnter(e) {
14741454
if (_this.#isLineEditing) {
14751455
if (_this.#editType === "add") {
14761456
elem.style.cursor = "crosshair"
@@ -1486,29 +1466,56 @@ class AnnotoriousAnnotator extends HTMLElement {
14861466
elem.style.cursor = "move"
14871467
cursorHandleElem.style.cursor = "move"
14881468
}
1489-
})
1490-
1491-
// Instead of click use mousedown and mouseup to accomodate moving a column during line editing mode
1492-
elem.addEventListener('mousedown', function(e) {
1493-
mouseStart = [e.pageX, e.pageY]
1494-
})
1469+
}
14951470

1496-
// A click initiates a split or merge on the active line during line editing mode
1497-
elem.addEventListener('mouseup', function(e) {
1471+
function applyMouseUp(e) {
14981472
mouseFinish = [e.pageX, e.pageY]
14991473
if (mouseStart[0] !== mouseFinish[0] || mouseStart[1] !== mouseFinish[1]) return
15001474
if (e.button !== 0) return
1475+
console.log("Mouse Up Line Change")
15011476
_this.lineChange(e)
1502-
})
1477+
}
15031478

1504-
// Position the ruler element to be with the cursor
1505-
elem.addEventListener('mousemove', function(e) {
1479+
function applyMouseMove(e) {
15061480
const rect = elem.getBoundingClientRect()
15071481
ruler.style.left = (rect.x - _this.containerLeftOffset()) + "px"
15081482
ruler.style.top = (e.pageY - _this.containerTopOffset() - window.scrollY) + "px"
15091483
ruler.style.height = '1px'
15101484
ruler.style.width = rect.width + "px"
1511-
})
1485+
}
1486+
1487+
/**
1488+
* Cursor support for split line and merge line.
1489+
* Applys correct cursor when an Annotation is selected programmatically during split and merge.
1490+
*/
1491+
if (this.#isLineEditing) {
1492+
if (this.#editType === "add") {
1493+
elem.style.cursor = "crosshair"
1494+
cursorHandleElem.style.cursor = "crosshair"
1495+
ruler.style.display = "block"
1496+
} else if (this.#editType === "merge") {
1497+
elem.style.cursor = "cell"
1498+
cursorHandleElem.style.cursor = "cell"
1499+
} else {
1500+
elem.style.cursor = "move"
1501+
cursorHandleElem.style.cursor = "move"
1502+
}
1503+
} else {
1504+
elem.style.cursor = "move"
1505+
cursorHandleElem.style.cursor = "move"
1506+
}
1507+
1508+
// Further cursor support when user changes edit options while an Annotation is selected.
1509+
elem.addEventListener('mouseenter', applyMouseEnter)
1510+
1511+
// Instead of click use mousedown and mouseup to accomodate moving a column during line editing mode
1512+
elem.addEventListener('mousedown', setMouseStart)
1513+
1514+
// A click initiates a split or merge on the active line during line editing mode
1515+
elem.addEventListener('mouseup', applyMouseUp)
1516+
1517+
// Position the ruler element to be with the cursor
1518+
elem.addEventListener('mousemove', applyMouseMove)
15121519

15131520
}
15141521

0 commit comments

Comments
 (0)