Skip to content

Commit

Permalink
refactor(IText): extract draggable text logic to a delegate/manager (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Mar 16, 2024
1 parent 7567959 commit 74574ee
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 427 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- fix(): regression of canvas migration with pointer and sendPointToPlane [#8563](https://github.com/fabricjs/fabric.js/pull/8563)
\- chore(TS): Add declare in front of properties that are type definitions. [#8574](https://github.com/fabricjs/fabric.js/pull/8574)
- refactor(Animation): modernize IText cursor animation based on animation API changes (and fix minor regression) plus leftovers from #8547 [#8583](https://github.com/fabricjs/fabric.js/pull/8583)
- refactor(IText): extract draggable text logic to a delegate [#8598](https://github.com/fabricjs/fabric.js/pull/8598)
- chore(TS): Update StaticCanvas to remove ts-nocheck [#8606](https://github.com/fabricjs/fabric.js/pull/8606)
- chore(TS): Update filters to remove ts-nocheck and added types where missing [#8609](https://github.com/fabricjs/fabric.js/pull/8609)
- chore(TS): Intersection class, finalize TS [#8603](https://github.com/fabricjs/fabric.js/pull/8603)
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/canvas.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type TDestroyedCanvas = Omit<
* flag = this.canDrop(opt.e);
* });
* b.canDrop = function(e) {
* !flag && this.callSuper('canDrop', e);
* !flag && this.draggableTextDelegate.canDrop(e);
* }
* b.on('dragover', opt => b.set('fill', opt.dropTarget === b ? 'pink' : 'black'));
* a.on('drop', opt => {
Expand Down
9 changes: 5 additions & 4 deletions src/canvas/canvas_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ export class Canvas extends SelectableCanvas {
// propagate the event to subtargets
for (let i = 0; i < targets.length; i++) {
const subTarget = targets[i];
// accept event only if previous targets didn't
// accept event only if previous targets didn't (the accepting target calls `preventDefault` to inform that the event is taken)
// TODO: verify if those should loop in inverse order then?
// what is the order of subtargets?
if (!e.defaultPrevented && subTarget.canDrop(e)) {
if (subTarget.canDrop(e)) {
dropTarget = subTarget;
}
subTarget.fire(eventType, options);
Expand Down Expand Up @@ -747,8 +747,9 @@ export class Canvas extends SelectableCanvas {
!this.allowTouchScrolling &&
(!activeObject ||
// a drag event sequence is started by the active object flagging itself on mousedown / mousedown:before
// we must not prevent the event's default behavior in order for the window to start the drag event sequence
!activeObject.__isDragging) &&
// we must not prevent the event's default behavior in order for the window to start dragging
(isFabricObjectWithDragSupport(activeObject) &&
!activeObject.shouldStartDragging())) &&
e.preventDefault &&
e.preventDefault();
this.__onMouseMove(e);
Expand Down

0 comments on commit 74574ee

Please sign in to comment.