Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: added OnInput event to support IME #183

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
protected placeholder: PixiText;
protected editing = false;
protected tick = 0;
protected lastInputData: string;

protected activation = false;
protected readonly options: InputOptions;
Expand All @@ -63,6 +64,7 @@
protected handleActivationBinding = this.handleActivation.bind(this);
protected onKeyUpBinding = this.onKeyUp.bind(this);
protected stopEditingBinding = this.stopEditing.bind(this);
protected onInputBinding = this.onInput.bind(this);

/** Fires when input loses focus. */
onEnter: Signal<(text: string) => void>;
Expand Down Expand Up @@ -126,6 +128,8 @@
window.addEventListener('click', this.handleActivationBinding);

window.addEventListener('keyup', this.onKeyUpBinding);

window.addEventListener('input', this.onInputBinding as EventListener);
}

this.onEnter = new Signal();
Expand All @@ -143,6 +147,11 @@
}
}

protected onInput(e: InputEvent)
{
this.lastInputData = e.data;
}

protected onKeyUp(e: KeyboardEvent)
{
const key = e.key;
Expand All @@ -155,7 +164,13 @@
{
this.stopEditing();
}
else if (key.length === 1) this._add(key);
else if (key.length === 1)
{
this._add(key);
}
else if (this.lastInputData && this.lastInputData.length === 1) {

Check warning on line 171 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
this._add(this.lastInputData);
}
}

protected init()
Expand Down Expand Up @@ -332,6 +347,7 @@
{
this.input.removeEventListener('blur', this.stopEditingBinding);
this.input.removeEventListener('keyup', this.onKeyUpBinding);
this.input.removeEventListener('input', this.onInputBinding as EventListener);

this.input?.blur();
this.input?.remove();
Expand Down Expand Up @@ -369,6 +385,7 @@

input.addEventListener('blur', this.stopEditingBinding);
input.addEventListener('keyup', this.onKeyUpBinding);
input.addEventListener('input', this.onInputBinding as EventListener);

this.input = input;

Expand Down Expand Up @@ -558,6 +575,8 @@
window.removeEventListener('click', this.handleActivationBinding);

window.removeEventListener('keyup', this.onKeyUpBinding);

window.removeEventListener('input', this.onInputBinding as EventListener);
}

super.destroy(options);
Expand Down
Loading