Skip to content

Commit

Permalink
Fix text input focus messing with the input manager
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Oct 4, 2024
1 parent 524ca4d commit f4544a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Extensions/TextInput/textinputruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ namespace gdjs {
}

focus(): void {
if (!this.isFocused()) {
// If the input was not previously focused, reset input manager because there is
// no reason to maintain its state. It avoids bugs where a key is pressed, the text
// input is focused and then the input manager does not have access to the keyup event
// and considers the key still pressed.
this.getInstanceContainer()
.getGame()
.getInputManager()
.clearAllPressedKeys();
}
this._renderer.focus();
}
}
Expand Down
8 changes: 8 additions & 0 deletions GDJS/Runtime/inputmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,14 @@ namespace gdjs {
return this.getMouseWheelDelta() < 0;
}

/**
* Clears all stored pressed keys without making the keys go through
* the release state.
*/
clearAllPressedKeys(): void {
this._pressedKeys.clear();
}

static _allTouchIds: Array<integer> = [];
}
}

0 comments on commit f4544a4

Please sign in to comment.