Skip to content

Commit 377b8f2

Browse files
committed
[salgum1114#209] Change code in keydown event
1 parent b3f0aad commit 377b8f2

File tree

9 files changed

+202
-171
lines changed

9 files changed

+202
-171
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-design-editor",
3-
"version": "0.0.33",
3+
"version": "0.0.34",
44
"description": "Design Editor Tools with React.js + ant.design + fabric.js",
55
"main": "dist/react-design-editor.min.js",
66
"typings": "lib/index.d.ts",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const ESCAPE = 'Escape';
2+
export const DELETE = 'Delete';
3+
export const BACKSPACE = 'Backspace';
4+
export const EQUAL = 'Equal';
5+
export const MINUS = 'Minus';
6+
export const KEY_A = 'KeyA';
7+
export const KEY_Q = 'KeyQ';
8+
export const KEY_W = 'KeyW';
9+
export const KEY_C = 'KeyC';
10+
export const KEY_V = 'KeyV';
11+
export const KEY_Z = 'KeyZ';
12+
export const KEY_Y = 'KeyY';
13+
export const KEY_O = 'KeyO';
14+
export const KEY_P = 'KeyP';
15+
export const KEY_X = 'KeyX';
16+
export const ARROW_UP = 'ArrowUp';
17+
export const ARROW_DOWN = 'ArrowDown';
18+
export const ARROW_LEFT = 'ArrowLeft';
19+
export const ARROW_RIGHT = 'ArrowRight';
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import * as defaults from './defaults';
2+
import * as code from './code';
23

3-
export { defaults };
4+
export { defaults, code };

src/components/canvas/handlers/EventHandler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Handler from './Handler';
55
import { FabricObject, FabricEvent } from '../utils';
66
import { VideoObject } from '../objects/Video';
77
import { NodeObject } from '../objects/Node';
8+
import { code } from '../constants';
89

910
/**
1011
* Event Handler Class
@@ -13,7 +14,7 @@ import { NodeObject } from '../objects/Node';
1314
*/
1415
class EventHandler {
1516
handler: Handler;
16-
keyCode: number;
17+
code: string;
1718
panning: boolean;
1819

1920
constructor(handler: Handler) {
@@ -293,22 +294,22 @@ class EventHandler {
293294
if (activeObject.id === 'workarea') {
294295
return false;
295296
}
296-
if (e.keyCode === 38) {
297+
if (e.code === code.ARROW_UP) {
297298
activeObject.set('top', activeObject.top - 2);
298299
activeObject.setCoords();
299300
this.handler.canvas.renderAll();
300301
return true;
301-
} else if (e.keyCode === 40) {
302+
} else if (e.code === code.ARROW_DOWN) {
302303
activeObject.set('top', activeObject.top + 2);
303304
activeObject.setCoords();
304305
this.handler.canvas.renderAll();
305306
return true;
306-
} else if (e.keyCode === 37) {
307+
} else if (e.code === code.ARROW_LEFT) {
307308
activeObject.set('left', activeObject.left - 2);
308309
activeObject.setCoords();
309310
this.handler.canvas.renderAll();
310311
return true;
311-
} else if (e.keyCode === 39) {
312+
} else if (e.code === code.ARROW_RIGHT) {
312313
activeObject.set('left', activeObject.left + 2);
313314
activeObject.setCoords();
314315
this.handler.canvas.renderAll();
@@ -644,7 +645,7 @@ class EventHandler {
644645
* @param {ClipboardEvent} e
645646
* @returns
646647
*/
647-
public paste = (e: ClipboardEvent) => {
648+
public paste = async (e: ClipboardEvent) => {
648649
if (this.handler.canvas.wrapperEl !== document.activeElement) {
649650
return false;
650651
}
@@ -772,7 +773,7 @@ class EventHandler {
772773
return;
773774
}
774775
if (this.handler.shortcutHandler.isW(e)) {
775-
this.keyCode = e.keyCode;
776+
this.code = e.code;
776777
this.handler.interactionHandler.grab();
777778
return;
778779
}
@@ -792,7 +793,7 @@ class EventHandler {
792793
}
793794
if (editable) {
794795
if (this.handler.shortcutHandler.isQ(e)) {
795-
this.keyCode = e.keyCode;
796+
this.code = e.code;
796797
} else if (this.handler.shortcutHandler.isDelete(e)) {
797798
this.handler.remove();
798799
} else if (this.handler.shortcutHandler.isArrow(e)) {

src/components/canvas/handlers/Handler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ class Handler implements HandlerOptions {
285285

286286
private isRequsetAnimFrame = false;
287287
private requestFrame: any;
288+
/**
289+
* Copied object
290+
*
291+
* @private
292+
* @type {*}
293+
*/
288294
private clipboard: any;
289295

290296
constructor(options: HandlerOptions) {

0 commit comments

Comments
 (0)