<commit_before>module BABYLON {
    export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
        camera: FreeCamera;

        @serialize()
        public buttons = [0, 1, 2];

        @serialize()
        public angularSensibility = 2000.0;

        private _pointerInput: (p: PointerInfo, s: EventState) => void;
        private _observer: Observer<PointerInfo>;

        constructor(public touchEnabled = true) {
        }

        attachControl(element: HTMLElement, noPreventDefault?: boolean) {
            var engine = this.camera.getEngine();

            if (!this._pointerInput) {
                var isPointerDown = false;
                this._pointerInput = (p, s) => {
                    var evt = <PointerEvent>p.event;

                    if (!this.touchEnabled && evt.pointerType === "touch") {
                        return;
                    }

                    if(p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1){
                        return;
                    }

                    if (p.type === PointerEventTypes.POINTERDOWN) {
                        try {
                            evt.srcElement.setPointerCapture(evt.pointerId);
                        } catch (e) {
                            //Nothing to do with the error. Execution will continue.
                        }

                        isPointerDown = true;

                        if (!noPreventDefault) {
                            evt.preventDefault();
                            element.focus();
                        }
                    }
                    else if (p.type === PointerEventTypes.POINTERUP) {
                        try {
                            evt.srcElement.releasePointerCapture(evt.pointerId);
                        } catch (e) {
                            //Nothing to do with the error.
                        }

                        isPointerDown = false;

                        if (!noPreventDefault) {
                            evt.preventDefault();
                        }
                    }

                    else if (p.type === PointerEventTypes.POINTERMOVE) {
                        if (!isPointerDown && !engine.isPointerLock) {
                            return;
                        }

                        var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                        var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;

                        if (this.camera.getScene().useRightHandedSystem) {
                            this.camera.cameraRotation.y -= offsetX / this.angularSensibility;
                        } else {
                            this.camera.cameraRotation.y += offsetX / this.angularSensibility;
                        }
                        this.camera.cameraRotation.x += offsetY / this.angularSensibility;

                        if (!noPreventDefault) {
                            evt.preventDefault();
                        }
                    }
                }
            }

            this._observer = this.camera.getScene().onPointerObservable.add(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);
        }

        detachControl(element: HTMLElement) {
            if (this._observer && element) {
                this.camera.getScene().onPointerObservable.remove(this._observer);
                this._observer = null;
            }
        }

        getTypeName(): string {
            return "FreeCameraMouseInput";
        }

        getSimpleName() {
            return "mouse";
        }
    }

    CameraInputTypes["FreeCameraMouseInput"] = FreeCameraMouseInput;
}
<commit_msg>Revert "Cleanup mouse move management"<commit_after>module BABYLON {
    export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
        camera: FreeCamera;

        @serialize()
        public buttons = [0, 1, 2];

        @serialize()
        public angularSensibility = 2000.0;

        private _pointerInput: (p: PointerInfo, s: EventState) => void;
        private _onMouseMove: (e: MouseEvent) => any;
        private _observer: Observer<PointerInfo>;

        private previousPosition: { x: number, y: number };

        constructor(public touchEnabled = true) {
        }

        attachControl(element: HTMLElement, noPreventDefault?: boolean) {
            var engine = this.camera.getEngine();

            if (!this._pointerInput) {
                this._pointerInput = (p, s) => {
                    var evt = <PointerEvent>p.event;

                    if (!this.touchEnabled && evt.pointerType === "touch") {
                        return;
                    }

                    if(p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(evt.button) === -1){
                        return;
                    }

                    if (p.type === PointerEventTypes.POINTERDOWN) {
                        try {
                            evt.srcElement.setPointerCapture(evt.pointerId);
                        } catch (e) {
                            //Nothing to do with the error. Execution will continue.
                        }

                        this.previousPosition = {
                            x: evt.clientX,
                            y: evt.clientY
                        };

                        if (!noPreventDefault) {
                            evt.preventDefault();
                            element.focus();
                        }
                    }
                    else if (p.type === PointerEventTypes.POINTERUP) {
                        try {
                            evt.srcElement.releasePointerCapture(evt.pointerId);
                        } catch (e) {
                            //Nothing to do with the error.
                        }

                        this.previousPosition = null;
                        if (!noPreventDefault) {
                            evt.preventDefault();
                        }
                    }

                    else if (p.type === PointerEventTypes.POINTERMOVE) {
                        if (!this.previousPosition || engine.isPointerLock) {
                            return;
                        }

                        var offsetX = evt.clientX - this.previousPosition.x;
                        var offsetY = evt.clientY - this.previousPosition.y;

                        if (this.camera.getScene().useRightHandedSystem) {
                            this.camera.cameraRotation.y -= offsetX / this.angularSensibility;
                        } else {
                            this.camera.cameraRotation.y += offsetX / this.angularSensibility;
                        }

                        this.camera.cameraRotation.x += offsetY / this.angularSensibility;

                        this.previousPosition = {
                            x: evt.clientX,
                            y: evt.clientY
                        };

                        if (!noPreventDefault) {
                            evt.preventDefault();
                        }
                    }
                }
            }

            this._onMouseMove = evt => {
                if (!engine.isPointerLock) {
                    return;
                }

                var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;

                if (this.camera.getScene().useRightHandedSystem) {
                    this.camera.cameraRotation.y -= offsetX / this.angularSensibility;
                } else {
                    this.camera.cameraRotation.y += offsetX / this.angularSensibility;
                }

                this.camera.cameraRotation.x += offsetY / this.angularSensibility;

                this.previousPosition = null;

                if (!noPreventDefault) {
                    evt.preventDefault();
                }
            };

            this._observer = this.camera.getScene().onPointerObservable.add(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);
            element.addEventListener("mousemove", this._onMouseMove, false);

        }

        detachControl(element: HTMLElement) {
            if (this._observer && element) {
                this.camera.getScene().onPointerObservable.remove(this._observer);
                element.removeEventListener("mousemove", this._onMouseMove);

                this._observer = null;
                this._onMouseMove = null;
                this.previousPosition = null;
            }
        }

        getTypeName(): string {
            return "FreeCameraMouseInput";
        }

        getSimpleName() {
            return "mouse";
        }
    }

    CameraInputTypes["FreeCameraMouseInput"] = FreeCameraMouseInput;
}

{'fraction_non_alphanumeric': 0.08762006403415155, 'fraction_numerical': 0.0023479188900747067, 'mean_word_length': 1.0917410714285714, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4664808', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2094, 'n_words': 379}