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"));
document.addEventListener("mousedown", this.#handleMousedown.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));
window.addEventListener("popstate", () => { 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);
sendText.textContent = sendText.getAttribute(`data-${textInput.value ? "send" : "back"}-content`);
textInput.focus();
}
#handleButtonClick(event) {
@ -113,10 +118,10 @@ export default class UI {
// normalize line endings
const text = textInput.value.replace(/\r\n?/g, "\n");
this.#inputController.keyboardText(text);
textInput.value = "";
this.#handleTextInput();
this.#updateTextInput("");
} else {
history.back();
}
history.back();
}
#showScene(scene) {
@ -160,8 +165,7 @@ export default class UI {
showTextInput() {
this.#showScene(textInputScene);
textInput.value = sessionStorage.getItem("text-input") || "";
textInput.focus();
this.#updateTextInput(sessionStorage.getItem("text-input") || "");
if (history.state != "text-input") {
history.pushState("text-input", "");
}

View file

@ -28,7 +28,7 @@
<textarea class="grow" cols=1 rows=1></textarea>
<div class="buttons">
<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>