From 790c833b68047983411ee03441d07f0d0cf7672c Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Wed, 5 Oct 2022 13:25:56 +0200 Subject: [PATCH 1/2] deal with dead codes correctly --- packages/dev/gui/src/2D/controls/inputText.ts | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/packages/dev/gui/src/2D/controls/inputText.ts b/packages/dev/gui/src/2D/controls/inputText.ts index a68615dfd13..a7c41a0b1f1 100644 --- a/packages/dev/gui/src/2D/controls/inputText.ts +++ b/packages/dev/gui/src/2D/controls/inputText.ts @@ -272,7 +272,7 @@ export class InputText extends Control implements IFocusableControl { this._markAsDirty(); } - /** Gets or sets the dead key flag */ + /** Gets or sets the dead key. 0 to disable. */ @serialize() public get deadKey(): boolean { return this._deadKey; @@ -696,28 +696,11 @@ export class InputText extends Control implements IFocusableControl { this._cursorIndex = -1; this._markAsDirty(); return; - case 222: // Dead - if (evt) { - //add support for single and double quotes - if (evt.code == "Quote") { - if (evt.shiftKey) { - keyCode = 34; - key = '"'; - } else { - keyCode = 39; - key = "'"; - } - } else { - evt.preventDefault(); - this._cursorIndex = -1; - this.deadKey = true; - } - } else { - this._cursorIndex = -1; - this.deadKey = true; - } - break; } + if (keyCode === 32) { + key = evt?.key ?? " "; + } + this._deadKey = key === "Dead"; // Printable characters if ( key && @@ -735,7 +718,8 @@ export class InputText extends Control implements IFocusableControl { this._currentKey = key; this.onBeforeKeyAddObservable.notifyObservers(this); key = this._currentKey; - if (this._addKey) { + console.log(key); + if (this._addKey && !this._deadKey) { if (this._isTextHighlightOn) { this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key); this._textHasChanged(); @@ -744,7 +728,8 @@ export class InputText extends Control implements IFocusableControl { this._blinkIsEven = false; this._markAsDirty(); } else if (this._cursorOffset === 0) { - this.text += key; + console.log("add to end"); + this.text += this._deadKey && evt?.key ? evt.key : key; } else { const insertPosition = this._textWrapper.length - this._cursorOffset; this._textWrapper.removePart(insertPosition, insertPosition, key); From deda71dcb9e79bf5018238052fcb08b3c45344f1 Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Wed, 5 Oct 2022 15:07:29 +0200 Subject: [PATCH 2/2] remove console output --- packages/dev/gui/src/2D/controls/inputText.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/dev/gui/src/2D/controls/inputText.ts b/packages/dev/gui/src/2D/controls/inputText.ts index a7c41a0b1f1..070c1ee3572 100644 --- a/packages/dev/gui/src/2D/controls/inputText.ts +++ b/packages/dev/gui/src/2D/controls/inputText.ts @@ -718,7 +718,6 @@ export class InputText extends Control implements IFocusableControl { this._currentKey = key; this.onBeforeKeyAddObservable.notifyObservers(this); key = this._currentKey; - console.log(key); if (this._addKey && !this._deadKey) { if (this._isTextHighlightOn) { this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key); @@ -728,7 +727,6 @@ export class InputText extends Control implements IFocusableControl { this._blinkIsEven = false; this._markAsDirty(); } else if (this._cursorOffset === 0) { - console.log("add to end"); this.text += this._deadKey && evt?.key ? evt.key : key; } else { const insertPosition = this._textWrapper.length - this._cursorOffset;