From 3f255cce34d18a3b337728267e23f33f5c0cd4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Mertel?= <10438157+jancimertel@users.noreply.github.com> Date: Sun, 10 Nov 2024 21:32:13 +0100 Subject: [PATCH] fix annotator selection, close #2433 --- packages/annotator/src/lib/Annotator.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/annotator/src/lib/Annotator.ts b/packages/annotator/src/lib/Annotator.ts index 8d39f7dd1..55c4cd024 100644 --- a/packages/annotator/src/lib/Annotator.ts +++ b/packages/annotator/src/lib/Annotator.ts @@ -680,7 +680,16 @@ export class Annotator { */ onMouseMove(e: MouseEvent) { if (this.cursor.isSelecting()) { + // move the cursor to selected position, but dont allow to move over the line boundaries (x axis) this.cursor.setPositionFromEvent(e, this.lineHeight, this.charWidth); + const segment = this.text.cursorToIndex(this.viewport, this.cursor); + if (segment) { + const line = this.text.getLineFromPosition(segment); + if (line.length < this.cursor.xLine) { + this.cursor.xLine = line.length; + } + } + this.cursor.selectArea(this.viewport.lineStart); this.draw(); } @@ -928,7 +937,6 @@ export class Annotator { for (const tag of annotated) { const hlSchema = this.onHighlightCb(tag); if (hlSchema) { - // iterate over all tag occurrences let occurence: IAbsCoordinates[]; let i = 1;