From: Christian Heller Date: Thu, 26 Nov 2020 22:55:19 +0000 (+0100) Subject: Fix input line recalculation bugs. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/add_task?a=commitdiff_plain;h=866ac7e6f0714ef7a0d97cd85d03dcee1e38f50f;p=plomrogue2 Fix input line recalculation bugs. --- diff --git a/rogue_chat.html b/rogue_chat.html index 1ab5afc..d2136df 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -658,7 +658,7 @@ let tui = { explorer.query_info(); } } - this.empty_input(); + this.inputEl.value = ""; this.restore_input_values(); for (let el of document.getElementsByTagName("button")) { el.disabled = true; @@ -748,34 +748,26 @@ let tui = { let info = explorer.info_db[explorer.position]; if (info != "(none)") { this.inputEl.value = info; - this.recalc_input_lines(); } } else if (this.mode.name == 'portal' && explorer.position in game.portals) { let portal = game.portals[explorer.position] this.inputEl.value = portal; - this.recalc_input_lines(); } else if (this.mode.name == 'password') { this.inputEl.value = this.password; - this.recalc_input_lines(); } else if (this.mode.name == 'name_thing') { let t = game.get_thing(this.selected_thing_id); if (t && t.name_) { this.inputEl.value = t.name_; - this.recalc_input_lines(); } } }, - empty_input: function(str) { - this.inputEl.value = ""; + recalc_input_lines: function() { if (this.mode.has_input_prompt) { - this.recalc_input_lines(); + let _ = null; + [this.input_lines, _] = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width); } else { - this.height_input = 0; + this.input_lines = []; } - }, - recalc_input_lines: function() { - let _ = null; - [this.input_lines, _] = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width); this.height_input = this.input_lines.length; }, msg_into_lines_of_width: function(msg, width) { @@ -1058,6 +1050,7 @@ let tui = { full_refresh: function() { this.links = {}; terminal.drawBox(0, 0, terminal.rows, terminal.cols); + this.recalc_input_lines(); if (this.mode.is_intro) { this.draw_history(); this.draw_input(); @@ -1256,7 +1249,6 @@ tui.inputEl.addEventListener('input', (event) => { if (tui.inputEl.value.length > max_length) { tui.inputEl.value = tui.inputEl.value.slice(0, max_length); }; - tui.recalc_input_lines(); } else if (tui.mode.name == 'write' && tui.inputEl.value.length > 0) { server.send(["TASK:WRITE", tui.inputEl.value[0], tui.password]); tui.switch_mode('edit'); @@ -1273,7 +1265,7 @@ tui.inputEl.addEventListener('keydown', (event) => { } if (tui.mode.has_input_prompt && event.key == 'Enter' && tui.inputEl.value == '/help') { tui.show_help = true; - tui.empty_input(); + tui.inputEl.value = ""; tui.restore_input_values(); } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help && !tui.mode.is_single_char_entry) { @@ -1281,7 +1273,7 @@ tui.inputEl.addEventListener('keydown', (event) => { } else if (tui.mode.name == 'login' && event.key == 'Enter') { tui.login_name = tui.inputEl.value; server.send(['LOGIN', tui.inputEl.value]); - tui.empty_input(); + tui.inputEl.value = ""; } else if (tui.mode.name == 'control_pw_pw' && event.key == 'Enter') { if (tui.inputEl.value.length == 0) { tui.log_msg('@ aborted'); @@ -1355,7 +1347,7 @@ tui.inputEl.addEventListener('keydown', (event) => { } else if (tui.inputEl.valuelength > 0) { server.send(['ALL', tui.inputEl.value]); } - tui.empty_input(); + tui.inputEl.value = ""; } else if (tui.mode.name == 'play') { if (tui.mode.mode_switch_on_key(event)) { null; diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index c4fa349..7ffee57 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -822,8 +822,8 @@ class TUI: def draw_screen(): stdscr.clear() + recalc_input_lines() if self.mode.has_input_prompt: - recalc_input_lines() draw_input() if self.mode.shows_info: draw_info()