fix: preserve annotations while resizing selection

This commit is contained in:
2026-07-13 13:43:14 +08:00
parent b69ef00013
commit 75c9b96fbf
6 changed files with 122 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
export interface AnnotationPoint {
x: number
y: number
}
interface PointCollection {
points: AnnotationPoint[]
}
// Annotations are stored relative to the selection origin. Resizing from the
// top or left moves that origin, so offset the local points in the opposite
// direction to keep them attached to the same screen pixels.
export function preserveAnnotationScreenPositions(
annotations: PointCollection[],
previousOrigin: AnnotationPoint,
nextOrigin: AnnotationPoint
) {
const dx = previousOrigin.x - nextOrigin.x
const dy = previousOrigin.y - nextOrigin.y
if (dx === 0 && dy === 0) return
for (const annotation of annotations) {
for (const point of annotation.points) {
point.x += dx
point.y += dy
}
}
}
+6 -1
View File
@@ -10,6 +10,7 @@ import saveIcon from '../assets/icons/save-local.svg?raw'
import saveRemoteIcon from '../assets/icons/save-remote.svg?raw'
import ftpIcon from '../assets/icons/ftp.svg?raw'
import uploadIcon from '../assets/icons/upload.svg?raw'
import { preserveAnnotationScreenPositions } from '../utils/annotationGeometry'
interface Props {
width: number
@@ -539,12 +540,16 @@ function resizeSelection(p: Point) {
right = clamp(right, 0, props.width)
top = clamp(top, 0, props.height)
bottom = clamp(bottom, 0, props.height)
rect.value = {
const nextRect = {
x: Math.min(left, right),
y: Math.min(top, bottom),
w: Math.abs(right - left),
h: Math.abs(bottom - top),
}
if (rect.value) {
preserveAnnotationScreenPositions(annotations.value, rect.value, nextRect)
}
rect.value = nextRect
}
function selectTool(tool: Tool) {