Forráskód Böngészése

fixed suggested changes

ssaket 6 éve
szülő
commit
c9152097d7

+ 30 - 17
gui/src/2D/advancedDynamicTexture.ts

@@ -1,4 +1,4 @@
-import { DynamicTexture, Nullable, Observer, Camera, Engine, KeyboardInfoPre, ClipboardEventTypes, ClipboardInfo, PointerInfoPre, PointerInfo, Layer, Viewport, Scene, Texture, KeyboardEventTypes, Vector3, Matrix, Vector2, Tools, PointerEventTypes, AbstractMesh, StandardMaterial, Color3 } from 'babylonjs';
+import { DynamicTexture, Nullable, Observer, Camera, Engine, KeyboardInfoPre, PointerInfoPre, PointerInfo, Layer, Viewport, Scene, Texture, KeyboardEventTypes, Vector3, Matrix, Vector2, Tools, PointerEventTypes, AbstractMesh, StandardMaterial, Color3, Observable, ClipboardInfo } from 'babylonjs';
 import { Container } from "./controls/container";
 import { Control } from "./controls/control";
 import { Style } from "./style";
@@ -17,17 +17,14 @@ export interface IFocusableControl {
      */
     onBlur(): void;
     /**
-     * Function called to let the control handle keyboard events
+     * Function called to let the control handle events,
+     * KeyboardEvent -> handles key events
+     * PointerEvent -> handles dbl click event and text highlight.
+     * ClipboardInfo -> handles copy, cut, paste events.
      * @param evt defines the current keyboard event
      */
-    processKeyboard(evt: KeyboardEvent): void;
-    /**
-     * Defines clipboard events
-     * @param {ClipboardEventsTypes} evt
-     */
-    onClipboardKeyBoardEvent(type: ClipboardEventTypes): void;
+    processKeyboard(evt: Event): void;
 
-    onClipboardPointerEvents(showHighlightedText: boolean): void;
     /**
      * Function called to get the list of controls that should not steal the focus from this control
      * @returns an array of controls
@@ -41,7 +38,6 @@ export interface IFocusableControl {
  */
 export class AdvancedDynamicTexture extends DynamicTexture {
     private _isDirty = false;
-    private _ctrKeyOn = false;
     private _renderObserver: Nullable<Observer<Camera>>;
     private _resizeObserver: Nullable<Observer<Engine>>;
     private _preKeyboardObserver: Nullable<Observer<KeyboardInfoPre>>;
@@ -75,6 +71,8 @@ export class AdvancedDynamicTexture extends DynamicTexture {
     private _blockNextFocusCheck = false;
     private _renderScale = 1;
     private _rootCanvas: Nullable<HTMLCanvasElement>;
+    private _clipboardData: DataTransfer;
+    public onClipboardObserver = new Observable<ClipboardInfo>();
 
     /**
      * Gets or sets a boolean defining if alpha is stored as premultiplied
@@ -244,6 +242,16 @@ export class AdvancedDynamicTexture extends DynamicTexture {
     }
 
     /**
+     * Gets or set information about clipboardData
+     */
+    public get clipboardData(): DataTransfer {
+        return this._clipboardData;
+    }
+    public set clipboardData(value: DataTransfer) {
+        this._clipboardData = value;
+    }
+
+     /**
      * Creates a new AdvancedDynamicTexture
      * @param name defines the name of the texture
      * @param width defines the width of the texture
@@ -265,19 +273,15 @@ export class AdvancedDynamicTexture extends DynamicTexture {
 
         this._renderObserver = scene.onBeforeCameraRenderObservable.add((camera: Camera) => this._checkUpdate(camera));
         this._preKeyboardObserver = scene.onPreKeyboardObservable.add((info) => {
-            if (!this._focusedControl || (!this._ctrKeyOn && (info.event.ctrlKey || info.event.metaKey))) {
-                this._ctrKeyOn = true;
+            if (!this._focusedControl) {
                 return;
             }
 
             if (info.type === KeyboardEventTypes.KEYDOWN) {
-                //get the event type
-                let type = ClipboardInfo.GetTypeFromCharacter(info.event);
-                (this._ctrKeyOn && type !== -1) ? this._focusedControl.onClipboardKeyBoardEvent(type) : this._focusedControl.processKeyboard(info.event);
+                this._focusedControl.processKeyboard(info.event);
             }
 
             info.skipOnPointerObservable = true;
-            this._ctrKeyOn = false;
         });
 
         this._rootContainer._link(null, this);
@@ -391,6 +395,8 @@ export class AdvancedDynamicTexture extends DynamicTexture {
         }
 
         this._rootContainer.dispose();
+        this.onClipboardObserver.clear();
+        this.clipboardData.clearData();
 
         super.dispose();
     }
@@ -605,7 +611,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
                 return;
             }
             //check for focused control and call the onClipboardPointerEvents
-            (this._focusedControl) ? ((pi.type === PointerEventTypes.POINTERDOUBLETAP) ? this._focusedControl.onClipboardPointerEvents(true) : null) : null;
+            (this._focusedControl) ? ((pi.type === PointerEventTypes.POINTERDOUBLETAP) ? this._focusedControl.processKeyboard(pi.event) : null) : null;
 
             if (pi.type !== PointerEventTypes.POINTERMOVE
                 && pi.type !== PointerEventTypes.POINTERUP
@@ -637,6 +643,13 @@ export class AdvancedDynamicTexture extends DynamicTexture {
             }
         });
 
+        this.onClipboardObserver.add((pi, state) => {
+            if (this.focusedControl) {
+                // call the event's callback
+                this.focusedControl.processKeyboard(pi.event);
+            }
+        });
+
         this._attachToOnPointerOut(scene);
     }
 

+ 21 - 44
gui/src/2D/controls/control.ts

@@ -1,7 +1,7 @@
 import { Container } from "./container";
 import { AdvancedDynamicTexture } from "../advancedDynamicTexture";
 import { ValueAndUnit } from "../valueAndUnit";
-import { Nullable, Observer, Vector2, AbstractMesh, Observable, Vector3, Scene, Tools, Matrix, PointerEventTypes, ClipboardInfo } from "babylonjs";
+import { Nullable, Observer, Vector2, AbstractMesh, Observable, Vector3, Scene, Tools, Matrix, PointerEventTypes, ClipboardInfo, ClipboardEventTypes } from "babylonjs";
 import { Measure } from "../measure";
 import { Style } from "../style";
 import { Matrix2D, Vector2WithInfo } from "../math2D";
@@ -80,8 +80,6 @@ export class Control {
     protected _disabledColor = "#9a9a9a";
     /** @hidden */
     public _tag: any;
-    /** @hidden */
-    private _clipboardData: DataTransfer;
 
     /** Gets or sets a boolean indicating if the control can be hit with pointer events */
     public isHitTestVisible = true;
@@ -157,6 +155,9 @@ export class Control {
    */
     public onAfterDrawObservable = new Observable<Control>();
 
+    /** Observable raised when the clipboard event is raised */
+    public onClipboardObservable: Nullable<Observer<ClipboardInfo>>;
+
     /** Gets or set information about font offsets (used to render and align text) */
     public get fontOffset(): { ascent: number, height: number, descent: number } {
         return this._fontOffset;
@@ -166,15 +167,6 @@ export class Control {
         this._fontOffset = offset;
     }
 
-     /** Gets or set information about font offsets (used to render and align text) */
-     public get clipboardData(): DataTransfer {
-        return this._clipboardData;
-    }
-
-    public set clipboardData(data: DataTransfer) {
-        this._clipboardData = data;
-    }
-
     /** Gets or sets alpha value for the control (1 means opaque and 0 means entirely transparent) */
     public get alpha(): number {
         return this._alpha;
@@ -1380,54 +1372,39 @@ export class Control {
         return false;
     }
 
-     /** @hidden */
-    public onClipboardCopy(evt: ClipboardEvent): void {
-        console.log(this._clipboardData!, "copy");
+    /** @hidden */
+    private onClipboardCopy = (evt: ClipboardEvent) => {
+        let ev = new ClipboardInfo(ClipboardEventTypes.COPY, evt);
+        this._host.onClipboardObserver.notifyObservers(ev);
         evt.preventDefault();
     }
      /** @hidden */
-    public onClipboardCut(evt: ClipboardEvent): void {
-        console.log("Cut ! " + this._clipboardData.getData("text/plain"));
+    private onClipboardCut = (evt: ClipboardEvent) => {
+        let ev = new ClipboardInfo(ClipboardEventTypes.CUT, evt);
+        this._host.onClipboardObserver.notifyObservers(ev);
         evt.preventDefault();
     }
-     /** @hidden */
-    public onClipboardPaste(evt: ClipboardEvent): void {
-        if (evt.clipboardData.types.indexOf('text/plain') > -1) {
-            var text = evt.clipboardData.getData('text/plain');
-            console.log(text);
-            evt.preventDefault();
-          }
+    /** @hidden */
+    private onClipboardPaste = (evt: ClipboardEvent) => {
+        let ev = new ClipboardInfo(ClipboardEventTypes.PASTE, evt);
+        this._host.onClipboardObserver.notifyObservers(ev);
     }
 
    /**
      * @hidden
      */
     protected registerClipboardEvents(): void {
-        //binds the current focusedControl item to actions
-        this.onClipboardCopy = this.onClipboardCopy.bind(this);
-        this.onClipboardCut = this.onClipboardCut.bind(this);
-        this.onClipboardPaste = this.onClipboardPaste.bind(this);
-
-        document.addEventListener("copy", this.onClipboardCopy, false);
-        document.addEventListener("cut", this.onClipboardCut, false);
-        document.addEventListener("paste", this.onClipboardPaste, false);
+        self.addEventListener("copy", this.onClipboardCopy, false);
+        self.addEventListener("cut", this.onClipboardCut, false);
+        self.addEventListener("paste", this.onClipboardPaste, false);
     }
     /**
      * @hidden
      */
     protected unRegisterClipboardEvents(): void {
-        document.removeEventListener("copy", this.onClipboardCopy);
-        document.removeEventListener("cut", this.onClipboardCut);
-        document.removeEventListener("paste", this.onClipboardPaste);
-    }
-
-    /**
-     * @hidden dispatchClipboardEvent
-    */
-    protected dispatchClipboardEvent(event: ClipboardInfo): void {
-            // custom copy as navigator.clipboard as well as clipboardData in ClipboardInit not supported!
-            this._clipboardData = event.clipboardData;
-            document.dispatchEvent(event.event);
+        self.removeEventListener("copy", this.onClipboardCopy);
+        self.removeEventListener("cut",  this.onClipboardCut);
+        self.removeEventListener("paste", this.onClipboardPaste);
     }
 
     private _prepareFont() {

+ 138 - 72
gui/src/2D/controls/inputText.ts

@@ -4,7 +4,6 @@ import { ValueAndUnit } from "../valueAndUnit";
 import { Nullable, Observable, Vector2, ClipboardEventTypes, ClipboardInfo } from "babylonjs";
 import { Measure } from "../measure";
 import { VirtualKeyboard } from "./virtualKeyboard";
-import { TextBlock } from './textBlock';
 
 /**
  * Class used to create input text control
@@ -31,6 +30,7 @@ export class InputText extends Control implements IFocusableControl {
     private _currentKey = "";
     private _isTextHighlightOn = false;
     private _textHighlightColor = "#d5e0ff";
+    private _highligherOpacity = 0.4;
     private _highlightedText = "";
     private _startHighlightIndex = 0;
     private _endHighlightIndex = 0;
@@ -49,8 +49,6 @@ export class InputText extends Control implements IFocusableControl {
     public onFocusObservable = new Observable<InputText>();
     /** Observable raised when the control loses the focus */
     public onBlurObservable = new Observable<InputText>();
-    /** Observable raised when the clipboard event is raised */
-    public onClipboardObservable = new Observable<InputText>();
 
     /** Gets or sets the maximum width allowed by the control */
     public get maxWidth(): string | number {
@@ -72,6 +70,32 @@ export class InputText extends Control implements IFocusableControl {
         }
     }
 
+    /** Gets and sets the text highlighter transparancy; default: 0.4 */
+    public get highligherOpacity(): number {
+        return this._highligherOpacity;
+    }
+
+    public set highligherOpacity(value: number) {
+        if (this._highligherOpacity === value) {
+            return;
+        }
+        this._highligherOpacity = value;
+        this._markAsDirty();
+    }
+
+    /** Gets and sets the text hightlight color */
+    public get textHighlightColor(): string {
+        return this._textHighlightColor;
+    }
+
+    public set textHighlightColor(value: string) {
+        if (this._textHighlightColor === value) {
+            return;
+        }
+        this._textHighlightColor = value;
+        this._markAsDirty();
+    }
+
     /** Gets or sets control margin */
     public get margin(): string {
         return this._margin.toString(this._host);
@@ -184,11 +208,10 @@ export class InputText extends Control implements IFocusableControl {
         this._deadKey = flag;
     }
 
-     /** Gets or sets the highlight text */
-     public get getHighlightedText(): string {
+    /** Gets or sets the highlight text */
+    public get getHighlightedText(): string {
         return this._highlightedText;
     }
-
     public set setHighlightedText(text: string) {
         if (this._highlightedText === text) {
             return;
@@ -315,6 +338,12 @@ export class InputText extends Control implements IFocusableControl {
 
     /** @hidden */
     public processKey(keyCode: number, key?: string, evt?: KeyboardEvent) {
+
+        //get the clipboard Event from the keycode, returns -1 if not found.
+        let clipboardEventType: ClipboardEventTypes = ClipboardInfo.GetTypeFromCharacter(keyCode);
+        if (evt && (evt.ctrlKey || evt.metaKey) && clipboardEventType !== -1) {
+            return;
+        }
         // Specific cases
         switch (keyCode) {
             case 32: //SPACE
@@ -327,6 +356,12 @@ export class InputText extends Control implements IFocusableControl {
                 break;
             case 8: // BACKSPACE
                 if (this._text && this._text.length > 0) {
+                    if (this._isTextHighlightOn) {
+                        this.text = this._text.slice(0, this._startHighlightIndex) + this._text.slice(this._endHighlightIndex);
+                        this._isTextHighlightOn = false;
+                        this._blinkIsEven = false;
+                        return;
+                    }
                     if (this._cursorOffset === 0) {
                         this.text = this._text.substr(0, this._text.length - 1);
                     } else {
@@ -341,6 +376,15 @@ export class InputText extends Control implements IFocusableControl {
                 }
                 return;
             case 46: // DELETE
+                if (this._isTextHighlightOn) {
+                    this.text = this._text.slice(0, this._startHighlightIndex) + this._text.slice(this._endHighlightIndex);
+                    let decrementor = (this._endHighlightIndex - this._startHighlightIndex);
+                    while (decrementor > 0 && this._cursorOffset > 0) {
+                        this._cursorOffset--;
+                    }
+                    this._isTextHighlightOn = false;
+                    return;
+                }
                 if (this._text && this._text.length > 0  && this._cursorOffset > 0) {
                     let deletePosition = this._text.length - this._cursorOffset;
                     this.text = this._text.slice(0, deletePosition) + this._text.slice(deletePosition + 1);
@@ -361,6 +405,14 @@ export class InputText extends Control implements IFocusableControl {
                 this._markAsDirty();
                 return;
             case 37: // LEFT
+                if (evt && evt.shiftKey) {
+                    if (!this._isTextHighlightOn) {
+                        this._isTextHighlightOn = true;
+                        this._endHighlightIndex = this._text.length - this._cursorOffset;
+                        this._startHighlightIndex = this._endHighlightIndex;
+                    }
+                    (this._startHighlightIndex < 0) ? 0 : --this._startHighlightIndex;
+                }
                 this._cursorOffset++;
                 if (this._cursorOffset > this._text.length) {
                     this._cursorOffset = this._text.length;
@@ -369,6 +421,14 @@ export class InputText extends Control implements IFocusableControl {
                 this._markAsDirty();
                 return;
             case 39: // RIGHT
+                if (evt && evt.shiftKey) {
+                    if (!this._isTextHighlightOn) {
+                        this._isTextHighlightOn = true;
+                        this._startHighlightIndex = this._text.length - this._cursorOffset;
+                        this._endHighlightIndex = this._startHighlightIndex;
+                    }
+                    (this._endHighlightIndex > this._text.length) ? this._text.length - 1 : ++this._endHighlightIndex;
+                }
                 this._cursorOffset--;
                 if (this._cursorOffset < 0) {
                     this._cursorOffset = 0;
@@ -383,6 +443,7 @@ export class InputText extends Control implements IFocusableControl {
                 this.deadKey = true;
                 break;
         }
+        this._isTextHighlightOn = false;
 
         // Printable characters
         if (key &&
@@ -407,67 +468,81 @@ export class InputText extends Control implements IFocusableControl {
             }
         }
     }
-
     /** @hidden */
-    public processKeyboard(evt: KeyboardEvent): void {
-        this.processKey(evt.keyCode, evt.key, evt);
+    private _processDblClick(evt: PointerEvent) {
+        //pre-find the start and end index of the word under cursor, speeds up the rendering
+        this._startHighlightIndex = this._text.length - this._cursorOffset;
+        this._endHighlightIndex = this._startHighlightIndex;
+        for (let rWord = /\w+/g, left = 1, right = 1; this._startHighlightIndex > 0 && this._endHighlightIndex < this._text.length && (left || right);) {
+            right = (this._text[this._endHighlightIndex].search(rWord) !== -1) ? ++this._endHighlightIndex : 0;
+            left =  (this._text[this._startHighlightIndex - 1 ].search(rWord) !== -1) ? --this._startHighlightIndex : 0;
+        }
+        this._isTextHighlightOn = true;
+        this._blinkIsEven = false;
     }
 
     /** @hidden */
-    public onClipboardPointerEvents(showHighlightedText: boolean): void {
-        if (!showHighlightedText) {
-            return;
-        }
-        this._isTextHighlightOn = true;
+    public processKeyboard(evt: KeyboardEvent | PointerEvent | ClipboardEvent): void {
+        // check the event type and call its action
+        (evt instanceof KeyboardEvent) ? this.processKey(evt.keyCode, evt.key, evt) :
+         ((evt instanceof PointerEvent) ? this._processDblClick(evt) : this._processClipboardEvent(evt));
+    }
+
+    /**
+     *  Callback in case of copy event, can be configured.
+     * @param {ClipboardEvent} ev
+     */
+    public onCopyText(ev: ClipboardEvent): void {
+        this._isTextHighlightOn = false;
+        ev.clipboardData.setData("text/plain", this._highlightedText);
+        this._host.clipboardData = ev.clipboardData;
+        console.log("copy succcessful");
     }
-     /** @hidden */
-    public onClipboardKeyBoardEvent(type: number) {
-        this.executeClipboardEvent(type, this._highlightedText);
+    /**
+     * Callback in case of cut event, can be configured.
+     * @param {ClipboardEvent} ev
+     */
+    public onCutText(ev: ClipboardEvent): void {
+        this.text = this._text.replace(this._highlightedText, "");
+        this._isTextHighlightOn = false;
+        ev.clipboardData.setData("text/plain", this._highlightedText);
+        this._host.clipboardData = ev.clipboardData;
+        console.log("cut succcessful");
     }
-    /** @hidden */
-    private _processDataTransfer(data: DataTransfer, text: string = ""): void {
-        //FOR TESTING: TODO: remove this in final version
-        let textbl = new TextBlock();
-        textbl.text = "text copied : " + text;
-        textbl.color = "white";
-        textbl.fontSize = 24;
-        textbl.top = this.topInPixels - 23;
-        this._host.addControl(textbl);
-        setTimeout(() => {textbl.dispose(); }, 2000);
-
-        //copy data to the custom DataTransfer object
-        data.setData("text/plain", text);
-    }
-
-     /** @hidden */
-    private executeClipboardEvent(type: ClipboardEventTypes, text: string): void {
-        this._simulateClipboardEvent(type, text);
-    }
-
-     /** @hidden */
-    private _simulateClipboardEvent(type: ClipboardEventTypes, text: string): void {
-         let ev;
-         switch (type){
-             case ClipboardEventTypes.COPY:
-                    ev = new ClipboardInfo(ClipboardEventTypes.COPY, new ClipboardEvent("copy")); //new ClipboardEvent("copy");
-                    this._processDataTransfer(ev.clipboardData, text);
-                    super.dispatchClipboardEvent(ev);
+    /**
+     * Callback in case of paste event, can be configured.
+     *  @param {ClipboardEvent} ev
+     */
+    public onPasteText(ev: ClipboardEvent): void {
+        let data: string = "";
+        if (ev.clipboardData) {
+            data = ev.clipboardData.getData("text/plain");
+            let insertPosition = this._text.length - this._cursorOffset;
+            this.text = this._text.slice(0, insertPosition) + data + this._text.slice(insertPosition);
+            console.log("paste succcessful");
+        }
+        if (this._host.clipboardData) {
+            this._host.clipboardData.setData("text/plain", data);
+        }
+    }
+
+    /**
+     * @hidden
+     * Currently placed at control level but can be moved to ADT if required.
+    */
+    private _processClipboardEvent(ev: ClipboardEvent): void {
+        // call the clipboard event's callback, invoked by ADT's onClipboardObserver
+         switch (ev.type){
+            case "copy":
+                    this.onCopyText(ev);
                     break;
-              case ClipboardEventTypes.CUT:
-                    ev = new ClipboardInfo(ClipboardEventTypes.CUT, new ClipboardEvent("cut", {dataType: 'text/plain', data: text }));
-                    this.text = this._text.replace(text, "");
-                    this._isTextHighlightOn = false;
-                    this._processDataTransfer(ev.clipboardData, text);
-                    super.dispatchClipboardEvent(ev);
+            case "cut":
+                    this.onCutText(ev);
                     break;
-               case ClipboardEventTypes.PASTE:
-                    if (this.clipboardData.items.length > 0) {
-                        let data = this.clipboardData.getData("text/plain");
-                        let insertPosition = this._text.length - this._cursorOffset;
-                        this.text = this._text.slice(0, insertPosition) + data + this._text.slice(insertPosition);
-                    }
+            case "paste":
+                    this.onPasteText(ev);
                     break;
-                default: return;
+            default: return;
          }
     }
 
@@ -602,15 +677,13 @@ export class InputText extends Control implements IFocusableControl {
                  //show the highlighted text
                 if (this._isTextHighlightOn) {
                     clearTimeout(this._blinkTimeout);
-                    this._blinkIsEven = true;
-
-                    let highlightCursorOffsetWidth = context.measureText(this.text.substring(this._startHighlightIndex + 1)).width;
+                    let highlightCursorOffsetWidth = context.measureText(this.text.substring(this._startHighlightIndex)).width;
                     let highlightCursorLeft = this._scrollLeft + this._textWidth - highlightCursorOffsetWidth;
-                    this._highlightedText = this.text.substring(this._startHighlightIndex + 1, this._endHighlightIndex);
+                    this._highlightedText = this.text.substring(this._startHighlightIndex, this._endHighlightIndex);
                     //for transparancy
-                    context.globalAlpha = 0.4;
+                    context.globalAlpha = this._highligherOpacity;
                     context.fillStyle = this._textHighlightColor;
-                    context.fillRect(highlightCursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, context.measureText(this.text.substring(this._startHighlightIndex + 1, this._endHighlightIndex)).width, this._fontOffset.height);
+                    context.fillRect(highlightCursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, context.measureText(this.text.substring(this._startHighlightIndex, this._endHighlightIndex)).width, this._fontOffset.height);
                     context.globalAlpha = 1.0;
                 }
             }
@@ -655,13 +728,6 @@ export class InputText extends Control implements IFocusableControl {
 
     public _onPointerUp(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, notifyClick: boolean): void {
         super._onPointerUp(target, coordinates, pointerId, buttonIndex, notifyClick);
-
-        //pre-find the start and end index of the word under cursor, speeds up the rendering
-        this._startHighlightIndex = this._text.length - this._cursorOffset;
-        this._endHighlightIndex = this._startHighlightIndex;
-        for (let rWord = /\w+/, check = 1; this._startHighlightIndex >= 0 && this._endHighlightIndex < this.text.length && check + 1;) {
-            check = rWord.test(this.text.charAt(this._endHighlightIndex)) ? ++this._endHighlightIndex : (rWord.test(this.text.charAt(this._startHighlightIndex)) ? --this._startHighlightIndex : -1);
-        }
     }
 
     protected _beforeRenderText(text: string): string {
@@ -674,6 +740,6 @@ export class InputText extends Control implements IFocusableControl {
         this.onBlurObservable.clear();
         this.onFocusObservable.clear();
         this.onTextChangedObservable.clear();
-        this.onClipboardObservable.clear();
+        // this.onClipboardObservable.clear();
     }
 }

+ 7 - 8
src/Events/babylon.clipboardEvents.ts

@@ -30,7 +30,6 @@ module BABYLON {
          *Creates an instance of ClipboardInfo.
          * @param {number} type
          * @param {ClipboardEvent} event
-         * @memberof ClipboardInfo
          */
         constructor(
             /**
@@ -66,13 +65,13 @@ module BABYLON {
             this._clipboardData = value;
         }
 
-        /**
-         * This method is used to get the clipboard event type from the event.key
-         * @param {KeyboardEvent} e  triggered keyboard event
-         * @returns {number} clipboard event type (BABYLON.ClipboardEventTypes)
-         */
-        public static GetTypeFromCharacter(e: KeyboardEvent): number {
-            let charCode = (typeof e.which == "number") ? e.which : e.keyCode;
+       /**
+        *  Get the clipboard event's type from the keycode.
+        * @param keyCode
+        * @return {number}
+        */
+        public static GetTypeFromCharacter(keyCode: number): number {
+            let charCode = keyCode;
             //TODO: add codes for extended ASCII
             switch (charCode){
                 case 67: return ClipboardEventTypes.COPY;