Skip to content

Commit

Permalink
Fix backspace and use key event property for keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 4, 2017
1 parent 8bdd987 commit a49992d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
15 changes: 8 additions & 7 deletions js/jquery.terminal-0.11.23.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 04 Feb 2017 21:42:43 +0000
* Date: Sat, 04 Feb 2017 22:12:22 +0000
*/

/* TODO:
Expand Down Expand Up @@ -1556,7 +1556,7 @@
// ---------------------------------------------------------------------
// :: Keydown Event Handler
// ---------------------------------------------------------------------
var shift_insert;
var skip_insert;
function keydown_event(e) {
var result;
if (enabled) {
Expand All @@ -1568,7 +1568,7 @@
}
}
var key = get_key(e);
shift_insert = key === 'SHIFT+INSERT';
skip_insert = ['SHIFT+INSERT', 'BACKSPACE'].indexOf(key) !== -1;
if (e.which !== 38 &&
!(e.which === 80 && e.ctrlKey)) {
first_up_history = true;
Expand Down Expand Up @@ -1854,6 +1854,7 @@
if (!reverse_search && $.isFunction(options.keypress)) {
result = options.keypress(e);
}
var key = event.key || String.fromCharCode(e.which);
//$.terminal.active().echo(JSON.stringify(result));
if (result === undefined || result) {
if (enabled) {
Expand All @@ -1867,11 +1868,11 @@
} else if (!e.ctrlKey && !(e.altKey && e.which === 100) ||
e.altKey) { // ALT+D
if (reverse_search) {
rev_search_str += String.fromCharCode(e.which);
rev_search_str += key;
reverse_history_search();
draw_reverse_prompt();
} else {
self.insert(String.fromCharCode(e.which));
self.insert(key);
}
return false;
}
Expand All @@ -1881,8 +1882,8 @@
}
}
function input(e) {
if (no_keypress && !shift_insert) {
// shift insert don't fire keypress on Linux/Chrome
if (no_keypress && !skip_insert) {
// shift insert and backspace don't fire keypress on Linux/Chrome
// Some Androids don't fire keypress - #39
var val = clip.val();
if (val !== '' || e.which === 8) { // #209 ; 8 - backspace
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.terminal-0.11.23.min.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@
// ---------------------------------------------------------------------
// :: Keydown Event Handler
// ---------------------------------------------------------------------
var shift_insert;
var skip_insert;
function keydown_event(e) {
var result;
if (enabled) {
Expand All @@ -1568,7 +1568,7 @@
}
}
var key = get_key(e);
shift_insert = key === 'SHIFT+INSERT';
skip_insert = ['SHIFT+INSERT', 'BACKSPACE'].indexOf(key) !== -1;
if (e.which !== 38 &&
!(e.which === 80 && e.ctrlKey)) {
first_up_history = true;
Expand Down Expand Up @@ -1854,6 +1854,7 @@
if (!reverse_search && $.isFunction(options.keypress)) {
result = options.keypress(e);
}
var key = event.key || String.fromCharCode(e.which);
//$.terminal.active().echo(JSON.stringify(result));
if (result === undefined || result) {
if (enabled) {
Expand All @@ -1867,11 +1868,11 @@
} else if (!e.ctrlKey && !(e.altKey && e.which === 100) ||
e.altKey) { // ALT+D
if (reverse_search) {
rev_search_str += String.fromCharCode(e.which);
rev_search_str += key;
reverse_history_search();
draw_reverse_prompt();
} else {
self.insert(String.fromCharCode(e.which));
self.insert(key);
}
return false;
}
Expand All @@ -1881,8 +1882,8 @@
}
}
function input(e) {
if (no_keypress && !shift_insert) {
// shift insert don't fire keypress on Linux/Chrome
if (no_keypress && !skip_insert) {
// shift insert and backspace don't fire keypress on Linux/Chrome
// Some Androids don't fire keypress - #39
var val = clip.val();
if (val !== '' || e.which === 8) { // #209 ; 8 - backspace
Expand Down
15 changes: 8 additions & 7 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 04 Feb 2017 21:42:43 +0000
* Date: Sat, 04 Feb 2017 22:12:22 +0000
*/

/* TODO:
Expand Down Expand Up @@ -1556,7 +1556,7 @@
// ---------------------------------------------------------------------
// :: Keydown Event Handler
// ---------------------------------------------------------------------
var shift_insert;
var skip_insert;
function keydown_event(e) {
var result;
if (enabled) {
Expand All @@ -1568,7 +1568,7 @@
}
}
var key = get_key(e);
shift_insert = key === 'SHIFT+INSERT';
skip_insert = ['SHIFT+INSERT', 'BACKSPACE'].indexOf(key) !== -1;
if (e.which !== 38 &&
!(e.which === 80 && e.ctrlKey)) {
first_up_history = true;
Expand Down Expand Up @@ -1854,6 +1854,7 @@
if (!reverse_search && $.isFunction(options.keypress)) {
result = options.keypress(e);
}
var key = event.key || String.fromCharCode(e.which);
//$.terminal.active().echo(JSON.stringify(result));
if (result === undefined || result) {
if (enabled) {
Expand All @@ -1867,11 +1868,11 @@
} else if (!e.ctrlKey && !(e.altKey && e.which === 100) ||
e.altKey) { // ALT+D
if (reverse_search) {
rev_search_str += String.fromCharCode(e.which);
rev_search_str += key;
reverse_history_search();
draw_reverse_prompt();
} else {
self.insert(String.fromCharCode(e.which));
self.insert(key);
}
return false;
}
Expand All @@ -1881,8 +1882,8 @@
}
}
function input(e) {
if (no_keypress && !shift_insert) {
// shift insert don't fire keypress on Linux/Chrome
if (no_keypress && !skip_insert) {
// shift insert and backspace don't fire keypress on Linux/Chrome
// Some Androids don't fire keypress - #39
var val = clip.val();
if (val !== '' || e.which === 8) { // #209 ; 8 - backspace
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

0 comments on commit a49992d

Please sign in to comment.