Keep text input open after sending

This commit is contained in:
Unrud 2024-01-31 09:33:10 +01:00
parent 7cff8286c8
commit f11cefc74c
2 changed files with 12 additions and 8 deletions

View file

@ -57,7 +57,7 @@ export default class UI {
(target) => target.classList.contains("touch-input")); (target) => target.classList.contains("touch-input"));
document.addEventListener("mousedown", this.#handleMousedown.bind(this)); document.addEventListener("mousedown", this.#handleMousedown.bind(this));
document.addEventListener("touchend", this.#handleTouchend.bind(this)); document.addEventListener("touchend", this.#handleTouchend.bind(this));
textInput.addEventListener("input", this.#handleTextInput.bind(this)); textInput.addEventListener("input", () => { this.#updateTextInput(); });
sendText.addEventListener("click", this.#handleSendText.bind(this)); sendText.addEventListener("click", this.#handleSendText.bind(this));
window.addEventListener("popstate", () => { this.#update(); }); window.addEventListener("popstate", () => { this.#update(); });
compat.addFullscreenchangeEventListener(() => { this.#update(); }); compat.addFullscreenchangeEventListener(() => { this.#update(); });
@ -98,8 +98,13 @@ export default class UI {
} }
} }
#handleTextInput() { #updateTextInput(newValue = null) {
if (newValue != null) {
textInput.value = newValue;
}
sessionStorage.setItem("text-input", textInput.value); sessionStorage.setItem("text-input", textInput.value);
sendText.textContent = sendText.getAttribute(`data-${textInput.value ? "send" : "back"}-content`);
textInput.focus();
} }
#handleButtonClick(event) { #handleButtonClick(event) {
@ -113,10 +118,10 @@ export default class UI {
// normalize line endings // normalize line endings
const text = textInput.value.replace(/\r\n?/g, "\n"); const text = textInput.value.replace(/\r\n?/g, "\n");
this.#inputController.keyboardText(text); this.#inputController.keyboardText(text);
textInput.value = ""; this.#updateTextInput("");
this.#handleTextInput(); } else {
history.back();
} }
history.back();
} }
#showScene(scene) { #showScene(scene) {
@ -160,8 +165,7 @@ export default class UI {
showTextInput() { showTextInput() {
this.#showScene(textInputScene); this.#showScene(textInputScene);
textInput.value = sessionStorage.getItem("text-input") || ""; this.#updateTextInput(sessionStorage.getItem("text-input") || "");
textInput.focus();
if (history.state != "text-input") { if (history.state != "text-input") {
history.pushState("text-input", ""); history.pushState("text-input", "");
} }

View file

@ -28,7 +28,7 @@
<textarea class="grow" cols=1 rows=1></textarea> <textarea class="grow" cols=1 rows=1></textarea>
<div class="buttons"> <div class="buttons">
<button onclick="app.showKeys('text-input', 1)"></button> <button onclick="app.showKeys('text-input', 1)"></button>
<button class="grow" id="send-text"></button> <button class="grow" id="send-text" data-send-content="➣" data-back-content="⯇"></button>
</div> </div>
</div> </div>