Skip to content

Commit

Permalink
fix: not occur text changed event [#387, #419] (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
lja1018 committed Feb 22, 2021
1 parent 3bd25fa commit 9940d62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions apps/image-editor/src/js/component/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Text extends Component {
select: this._onFabricSelect.bind(this),
selectClear: this._onFabricSelectClear.bind(this),
scaling: this._onFabricScaling.bind(this),
textChanged: this._onFabricTextChanged.bind(this),
};

/**
Expand Down Expand Up @@ -113,7 +114,7 @@ class Text extends Component {
'selection:updated': this._listeners.select,
'before:selection:cleared': this._listeners.selectClear,
'object:scaling': this._listeners.scaling,
'text:editing': this._listeners.modify,
'text:changed': this._listeners.textChanged,
});

canvas.forEachObject((obj) => {
Expand Down Expand Up @@ -146,10 +147,12 @@ class Text extends Component {

canvas.off({
'mouse:down': this._listeners.mousedown,
'object:selected': this._listeners.select,
'selection:created': this._listeners.select,
'selection:updated': this._listeners.select,
'before:selection:cleared': this._listeners.selectClear,
'object:selected': this._listeners.select,
'object:scaling': this._listeners.scaling,
'text:editing': this._listeners.modify,
'text:changed': this._listeners.textChanged,
});
}

Expand Down Expand Up @@ -452,6 +455,15 @@ class Text extends Component {
obj.scaleY = 1;
}

/**
* textChanged event handler
* @param {{target: fabric.Object}} props - changed text object
* @private
*/
_onFabricTextChanged(props) {
this.fire(events.TEXT_CHANGED, props.target);
}

/**
* onSelectClear handler in fabric canvas
* @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event
Expand Down
6 changes: 3 additions & 3 deletions apps/image-editor/src/js/imageEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,11 @@ class ImageEditor {

/**
* 'textChanged' event handler
* @param {Object} objectProps changed object properties
* @param {Object} target - changed text object
* @private
*/
_onTextChanged(objectProps) {
this.changeText(objectProps.id, objectProps.text);
_onTextChanged(target) {
this.fire(events.TEXT_CHANGED, target);
}

/**
Expand Down

0 comments on commit 9940d62

Please sign in to comment.