Skip to content

Commit

Permalink
fix: not work spacebar key when vue component loaded [#560]
Browse files Browse the repository at this point in the history
  • Loading branch information
lja1018 committed Mar 25, 2021
1 parent 35ae13f commit dc6bf2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/image-editor/src/js/component/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ class Zoom extends Component {
this.graphics.on(ADD_TEXT, this._startTextEditingHandler.bind(this));
this.graphics.on(TEXT_EDITING, this._startTextEditingHandler.bind(this));
this.graphics.on(OBJECT_MODIFIED, this._stopTextEditingHandler.bind(this));
}

/**
* Attach zoom keyboard events
*/
attachKeyboardZoomEvents() {
fabric.util.addListener(document, KEY_DOWN, this._listeners.keydown);
fabric.util.addListener(document, KEY_UP, this._listeners.keyup);
}

/**
* Detach zoom keyboard events
*/
detachKeyboardZoomEvents() {
fabric.util.removeListener(document, KEY_DOWN, this._listeners.keydown);
fabric.util.removeListener(document, KEY_UP, this._listeners.keyup);
}

/**
* Handler when you started editing text
* @private
Expand Down
21 changes: 21 additions & 0 deletions apps/image-editor/src/js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Graphics {
this._createDrawingModeInstances();
this._createComponents();
this._attachCanvasEvents();
this._attachZoomEvents();
}

/**
Expand All @@ -173,6 +174,26 @@ class Graphics {
this._canvas.clear();

wrapperEl.parentNode.removeChild(wrapperEl);

this._detachZoomEvents();
}

/**
* Attach zoom events
*/
_attachZoomEvents() {
const zoom = this.getComponent(components.ZOOM);

zoom.attachKeyboardZoomEvents();
}

/**
* Detach zoom events
*/
_detachZoomEvents() {
const zoom = this.getComponent(components.ZOOM);

zoom.detachKeyboardZoomEvents();
}

/**
Expand Down

0 comments on commit dc6bf2c

Please sign in to comment.