Skip to content

Commit

Permalink
Merge pull request #13064 from RaananW/deadKeysTextInput
Browse files Browse the repository at this point in the history
[GUI] deal with dead codes correctly
  • Loading branch information
sebavan authored Oct 5, 2022
2 parents f5f2ecc + deda71d commit a9ed471
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions packages/dev/gui/src/2D/controls/inputText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand All @@ -735,7 +718,7 @@ export class InputText extends Control implements IFocusableControl {
this._currentKey = key;
this.onBeforeKeyAddObservable.notifyObservers(this);
key = this._currentKey;
if (this._addKey) {
if (this._addKey && !this._deadKey) {
if (this._isTextHighlightOn) {
this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key);
this._textHasChanged();
Expand All @@ -744,7 +727,7 @@ export class InputText extends Control implements IFocusableControl {
this._blinkIsEven = false;
this._markAsDirty();
} else if (this._cursorOffset === 0) {
this.text += key;
this.text += this._deadKey && evt?.key ? evt.key : key;
} else {
const insertPosition = this._textWrapper.length - this._cursorOffset;
this._textWrapper.removePart(insertPosition, insertPosition, key);
Expand Down

0 comments on commit a9ed471

Please sign in to comment.