Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: add existing object to group get wrong control position #10214

Open
7 tasks done
byeval opened this issue Oct 16, 2024 · 4 comments
Open
7 tasks done

[Bug]: add existing object to group get wrong control position #10214

byeval opened this issue Oct 16, 2024 · 4 comments
Labels

Comments

@byeval
Copy link

byeval commented Oct 16, 2024

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.0.2

In What environments are you experiencing the problem?

Chrome

Node Version (if applicable)

None

Link To Reproduction

https://codesandbox.io/p/sandbox/group-clippath-fabric-js-6-0-0-beta-14-forked-8zzx2r?file=%2Fsrc%2Findex.js%3A36%2C21

Steps To Reproduce

  1. create a group and a blue rect
  2. add blue rect to existing group
  3. reselect the blue rect, you can see it has a wrong control position

Expected Behavior

control is fit with object

Actual Behavior

control has wrong position
image

Error Message & Stack Trace

No response

@asturur
Copy link
Member

asturur commented Oct 16, 2024

The bug happens only if you do it inside object:modified. not if you just exec the code one step after another.
Need to look into it

@asturur asturur added the bug label Oct 16, 2024
@byeval
Copy link
Author

byeval commented Oct 18, 2024

@asturur Thank you for your reply! You are right, but I want switch object's artboard when user is dragging object in modify callback, Do you know how to solve this problem.

@zhe-he
Copy link
Contributor

zhe-he commented Oct 21, 2024

@asturur Thank you for your reply! You are right, but I want switch object's artboard when user is dragging object in modify callback, Do you know how to solve this problem.

@byeval
Can you check if this method meets your requirements? When you drag multiple items to the target group(XXX), you need to first remove them from ac. When you drag a single item, you need to reset the cache.

canvas.on("mouse:move", e => {
    const target = e.target;
    if (!canvas.selection) return;
    if (e.transform?.action != "drag") return;
    if (!target) return;
    const isA = target instanceof ActiveSelection;

    const fn = (o: FabricObject) => {
       (o.group ?? canvas).remove(o);
       // XXX -> The "XXX" in your example  === group
       XXX.add(o);
    }
    if (isA) {
        const list = target.getObjects();
        for (const item of list) {
            target.remove(item);
            fn(item);
            target.add(item);
        }
    } else {
        canvas._activeObject = undefined;
        canvas._hoveredTarget = undefined;
        fn(target);
        canvas._activeObject = target;
        canvas._hoveredTarget = target;
        canvas._setupCurrentTransform(e.e, target, true);
    }

});

@byeval
Copy link
Author

byeval commented Oct 23, 2024

@zhe-he It works! Thank you so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants