fix a couple of subtle backwards compatibility bugs

This commit is contained in:
Brenden Tuck 2019-04-01 22:09:18 -04:00
parent 0ca3bdae9f
commit 40b77b2eb8
2 changed files with 23 additions and 19 deletions

View file

@ -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');

View file

@ -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();