From 40b77b2eb8ca8d2b840ea4a11b2ea8832a85238c Mon Sep 17 00:00:00 2001 From: Brenden Tuck Date: Mon, 1 Apr 2019 22:09:18 -0400 Subject: [PATCH] fix a couple of subtle backwards compatibility bugs --- .../static/webclient/js/plugins/default_in.js | 25 +++++++++++++------ .../static/webclient/js/plugins/history.js | 17 +++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/evennia/web/webclient/static/webclient/js/plugins/default_in.js b/evennia/web/webclient/static/webclient/js/plugins/default_in.js index 0c19db9f4d..83aeb96a06 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/default_in.js +++ b/evennia/web/webclient/static/webclient/js/plugins/default_in.js @@ -11,6 +11,10 @@ let defaultin_plugin = (function () { // find where the key comes from var inputfield = $(".inputfield:focus"); + if( inputfield.length < 1 ) { // non-goldenlayout backwards compatibility + inputfield = $("#inputfield:focus"); + } + // check for important keys switch (event.which) { case 9: // ignore tab key -- allows normal focus control @@ -22,13 +26,13 @@ let defaultin_plugin = (function () { break; case 13: // Enter key - var outtext = inputfield.val(); + var outtext = inputfield.val(); // Grab the text from which-ever inputfield is focused if ( outtext && !event.shiftKey ) { // Enter Key without shift --> send Mesg var lines = outtext.trim().replace(/[\r]+/,"\n").replace(/[\n]+/, "\n").split("\n"); for (var i = 0; i < lines.length; i++) { plugin_handler.onSend( lines[i].trim() ); } - inputfield.val(''); + inputfield.val(''); // Clear this inputfield event.preventDefault(); } inputfield.blur(); @@ -36,10 +40,15 @@ let defaultin_plugin = (function () { // Anything else, focus() a textarea if needed, and allow the default event default: - // is anything actually focused? if not, focus the first .inputfield found in the DOM - if( !inputfield.hasClass('inputfield') ) { - // :first only matters if dual_input or similar multi-input plugins are in use - $('.inputfield:last').focus(); + // is an inputfield actually focused? + if( inputfield.length < 1 ) { + // Nope, focus the last .inputfield found in the DOM (or #inputfield) + // :last only matters if multi-input plugins are in use + inputfield = $(".inputfield:last") + inputfield.focus(); + if( inputfield.length < 1 ) { // non-goldenlayout backwards compatibility + $("#inputfield").focus(); + } } } @@ -49,13 +58,13 @@ let defaultin_plugin = (function () { // // Mandatory plugin init function var init = function () { - // Handle pressing the send button + // Handle pressing the send button, this only applies to non-goldenlayout setups $("#inputsend") .bind("click", function (evnt) { // simulate a carriage return var e = $.Event( "keydown" ); e.which = 13; - $('.inputfield:last').trigger(e); + $("#inputfield").focus().trigger(e); }); console.log('DefaultIn initialized'); diff --git a/evennia/web/webclient/static/webclient/js/plugins/history.js b/evennia/web/webclient/static/webclient/js/plugins/history.js index c68d2b77a5..8afcec44f3 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/history.js +++ b/evennia/web/webclient/static/webclient/js/plugins/history.js @@ -42,15 +42,6 @@ let history_plugin = (function () { history_pos = 0; } - // - // Add input to the scratch line - var scratch = function (input) { - // Put the input into the last history entry (which is normally empty) - // without making the array larger as with add. - // Allows for in-progress editing to be saved. - history[history.length-1] = input; - } - // Public // @@ -58,7 +49,6 @@ let history_plugin = (function () { var onKeydown = function(event) { var code = event.which; var history_entry = null; - var inputfield = $('.inputfield:focus'); // Only process up/down arrow if cursor is at the end of the line. if (code === 38 && event.shiftKey) { // Arrow up @@ -70,7 +60,12 @@ let history_plugin = (function () { // are we processing an up or down history event? if (history_entry !== null) { - // Doing a history navigation; replace the text in the input and move the cursor to the end of the new value + // Doing a history navigation; replace the text in the input and + // move the cursor to the end of the new value + var inputfield = $('.inputfield:focus'); + if( inputfield.length < 1 ) { // pre-goldenlayout backwards compatibility + inputfield = $('#inputfield'); + } inputfield.val(''); inputfield.blur().focus().val(history_entry); event.preventDefault();