mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-17 06:20:24 +00:00
fixes deep cloning of style (#3502)
* fixes deep cloning of style * better fix and tests
This commit is contained in:
parent
b775323424
commit
549ea1776b
3 changed files with 20 additions and 8 deletions
|
|
@ -628,7 +628,7 @@
|
|||
}
|
||||
for (var i = 0, len = _chars.length; i < len; i++) {
|
||||
if (useCopiedStyle) {
|
||||
style = fabric.copiedTextStyle[i];
|
||||
style = fabric.util.object.clone(fabric.copiedTextStyle[i], true);
|
||||
}
|
||||
this.insertChar(_chars[i], i < len - 1, style);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,12 +198,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
}
|
||||
|
||||
fabric.copiedText = selectedText;
|
||||
fabric.copiedTextStyle = fabric.util.object.clone(
|
||||
this.getSelectionStyles(
|
||||
this.selectionStart,
|
||||
this.selectionEnd
|
||||
)
|
||||
);
|
||||
fabric.copiedTextStyle = this.getSelectionStyles(this.selectionStart, this.selectionEnd);
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
this._copyDone = true;
|
||||
|
|
|
|||
|
|
@ -235,5 +235,22 @@
|
|||
equal(iText.selectionEnd, 31, 'should not move');
|
||||
selection = 0;
|
||||
});
|
||||
|
||||
test('copy and paste', function() {
|
||||
var event = { stopImmediatePropagation: function(){}, preventDefault: function(){} };
|
||||
var iText = new fabric.IText('test', { styles: { 0: { 0: { fill: 'red' }, 1: { fill: 'blue' }}}});
|
||||
iText.selectionStart = 0;
|
||||
iText.selectionEnd = 2;
|
||||
iText.copy(event);
|
||||
equal(fabric.copiedText, 'te', 'it copied first 2 characters');
|
||||
equal(fabric.copiedTextStyle[0], iText.styles[0][0], 'style is referenced');
|
||||
equal(fabric.copiedTextStyle[1], iText.styles[0][1], 'style is referenced');
|
||||
iText.selectionStart = 0;
|
||||
iText.selectionEnd = 0;
|
||||
iText.paste(event);
|
||||
equal(iText.text, 'tetest', 'text has been copied');
|
||||
notEqual(iText.styles[0][0], iText.styles[0][2], 'style is not referenced');
|
||||
notEqual(iText.styles[0][1], iText.styles[0][3], 'style is not referenced');
|
||||
deepEqual(iText.styles[0][0], iText.styles[0][2], 'style is copied');
|
||||
deepEqual(iText.styles[0][1], iText.styles[0][3], 'style is copied');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue