fix: preserve annotations while resizing selection
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user