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

IText Clone object, pass reference to style object instead of cloning it. #2396

Closed
rijint opened this issue Aug 8, 2015 · 6 comments · Fixed by #2407
Closed

IText Clone object, pass reference to style object instead of cloning it. #2396

rijint opened this issue Aug 8, 2015 · 6 comments · Fixed by #2407
Labels

Comments

@rijint
Copy link

rijint commented Aug 8, 2015

  1. Add an IText with some initial text eg:-sample, delete all characters(sample) using delete key/backspace key type new content (eg:-mytext).

  2. Take clone of edited IText

  3. Update color of single character the changes reflected to parent also
    change the color by selecting "my" in mytext

@asturur
Copy link
Member

asturur commented Aug 8, 2015

please post a fiddle, help us checking the bugs faster.

@rijint
Copy link
Author

rijint commented Aug 8, 2015

untitled
screenshot

@asturur
Copy link
Member

asturur commented Aug 8, 2015

Can you show us how you clone the itext? otherways is not possible to help you.

@rijint
Copy link
Author

rijint commented Aug 8, 2015

    var obj = canvas1.getActiveObject();

if (fabric.util.getKlass(obj.type).async) {
obj.clone(function (res) {
res.set({
left: 200,
top: 100
});
canvas1.add(res);
});
} else {
canvas1.add(obj.clone().set({left: 100, top: 100}));
}

@rihanrahul
Copy link

Here is the fiddle... http://jsfiddle.net/rihanrahul/6zmu0zce/

Please follow the steps mentioned above to reproduce the issue.

@asturur asturur changed the title IText Clone object property changes reflected to parent IText Clone object, pass reference to style object instead of cloning it. Aug 8, 2015
@asturur asturur added the bug label Aug 8, 2015
@asturur
Copy link
Member

asturur commented Aug 8, 2015

changing the util.extend function with something like this solve the problem

I m really not able to identify potential drawbacks here,
need @kangax help here. :)

  function extend(destination, source) {
    // JScript DontEnum bug is not taken care of
    for (var property in source) {
      var _source = source[property];
      if( Object.prototype.toString.call(_source) === '[object Array]' ) {
        destination[property] = extend([ ], _source);
      }
      else if (_source && typeof _source === 'object'){
        destination[property] = extend({ }, _source );
      }
      else {
        destination[property] = _source;
      }
    }
    return destination;
  }

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

Successfully merging a pull request may close this issue.

3 participants