fullstack-lang/gongsvg

Problem with anchor move

Closed this issue · 3 comments

Anchor move can be jittery. Width can become negative (with gondoc).

Steps:

  • reproduce issue in gongsvg
  • solve issue

Bug reproduction:

  • mousedown bottom rectangle
  • mouse move toward the top

Problem:

  • when the first mouse event fires, the anchor moves fast north

Analysis:

  • the problem seems completly related to the PageX & PageY. Indeed, when the top component is shrinked to 0, no more problem.
  anchorMouseMove(event: MouseEvent, anchor: 'left' | 'right' | 'top' | 'bottom'): void {
    event.stopPropagation(); // Prevent the event from bubbling up to the SVG element

    const x = event.clientX - this.pageX
    const y = event.clientY - this.pageY

    if (!event.altKey && !event.shiftKey) {
      let shapeMouseEvent: ShapeMouseEvent = {
        ShapeID: this.Rect!.ID,
        ShapeType: gongsvg.RectDB.GONGSTRUCT_NAME,
        Point: createPoint(x, y),
      }
      this.mouseEventService.emitMouseMoveEvent(shapeMouseEvent)
    }
  }

seems OK

          if (this.anchorDragging) {
            if (this.activeAnchor === 'left') {
              const originalRightEdge = this.Rect.X + this.Rect.Width
              this.Rect.X = shapeMouseEvent.Point.X
              this.Rect.Width = originalRightEdge - shapeMouseEvent.Point.X
            } else if (this.activeAnchor === 'right') {
              this.Rect.Width = shapeMouseEvent.Point.X - this.Rect.X
            } else if (this.activeAnchor === 'top') {
              const originalBottomEdge = this.Rect.Y + this.Rect.Height
              this.Rect.Y = shapeMouseEvent.Point.Y
              this.Rect.Height = originalBottomEdge - shapeMouseEvent.Point.Y
            } else if (this.activeAnchor === 'bottom') {
              this.Rect.Height = shapeMouseEvent.Point.Y - this.Rect.Y
            }
            return // we don't want the move move to be interpreted by the rect
          }

needs to be investigated.