fix: selection rect should reflect viewport change (#12355)

Fixes [BS-3349](https://linear.app/affine-design/issue/BS-3349/)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Improved edge scrolling during selection dragging for smoother and more responsive viewport navigation.
  - Dragging area and mouse position tracking now update reactively with viewport changes, ensuring more accurate selection and movement.

- **Refactor**
  - Unified and clarified coordinate handling for dragging and mouse position, with clearer naming and separation between model and browser coordinates.
  - Simplified selection logic and removed unnecessary accumulated state for cleaner and more maintainable behavior.
  - Enhanced flexibility in coordinate conversion by allowing viewport transformations relative to arbitrary zoom and center.
  - Streamlined clipboard paste handling by simplifying mouse position extraction and adjusting attachment options.

- **Bug Fixes**
  - Enhanced overlay and dragging area accuracy by updating position calculations and coordinate transformations.
  - Fixed paste operations to correctly handle mouse position without unnecessary coordinate conversions.
  - Corrected drag initiation positions in toolbar and shape dragging to align with viewport-relative coordinates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
doouding
2025-05-19 16:05:33 +00:00
parent fbe053a54e
commit eb185255a3
10 changed files with 188 additions and 135 deletions
+14 -2
View File
@@ -591,8 +591,20 @@ export class Viewport {
return new Bound(x, y, w / this.zoom, h / this.zoom);
}
toModelCoord(viewX: number, viewY: number): IVec {
const { viewportX, viewportY, zoom, viewScale } = this;
toModelCoord(
viewX: number,
viewY: number,
zoom = this.zoom,
center?: IPoint
): IVec {
const { viewScale } = this;
const viewportX = center
? center.x - this.width / 2 / zoom
: this.viewportX;
const viewportY = center
? center.y - this.height / 2 / zoom
: this.viewportY;
return [
viewportX + viewX / zoom / viewScale,
viewportY + viewY / zoom / viewScale,