allow tabbing from textboxes in forms.

This commit is contained in:
Christopher Jeffrey 2013-07-18 22:49:06 -05:00
parent df317bb472
commit 0f4b60314b
2 changed files with 20 additions and 9 deletions

View File

@ -3364,9 +3364,9 @@ function Form(options) {
this.screen._listenKeys(this);
this.screen.on('element keypress', function(el, ch, key) {
// Make sure we're not entering input into a textbox.
if (self.screen.grabKeys || self.screen.lockKeys) {
return;
}
// if (self.screen.grabKeys || self.screen.lockKeys) {
// return;
// }
// Make sure we're a form or input element.
if (el !== self && !el.hasAncestor(self)) {
@ -3376,6 +3376,14 @@ function Form(options) {
if ((key.name === 'tab' && !key.shift)
|| key.name === 'down'
|| (options.vi && key.name === 'j')) {
if (el.type === 'textbox' || el.type === 'textarea') {
if (key.name === 'j') return;
self.screen.grabKeys = false;
if (key.name === 'tab') {
// Workaround, since we can't stop the tab from being added.
el.emit('keypress', null, { name: 'backspace' });
}
}
self.focusNext();
return;
}
@ -3383,6 +3391,10 @@ function Form(options) {
if ((key.name === 'tab' && key.shift)
|| key.name === 'up'
|| (options.vi && key.name === 'k')) {
if (el.type === 'textbox' || el.type === 'textarea') {
if (key.name === 'k') return;
self.screen.grabKeys = false;
}
self.focusPrevious();
return;
}
@ -3665,7 +3677,7 @@ Textbox.prototype._listener = function(ch, key) {
if (this.value.length) {
this.value = this.value.slice(0, -1);
if (this.secret) return;
if (this.value.length < width - 1) {
if (this.value.length < width - 1) {
this.screen.program.cub();
}
}
@ -3674,11 +3686,6 @@ Textbox.prototype._listener = function(ch, key) {
// Tabs only work with textareas.
if (ch === '\t') ch = ' ';
this.value += ch;
if (this.content.indexOf('defined') !== -1) {
this.program.normalBuffer();
console.log(this.value);
process.exit(0);
}
if (this.secret) return;
if (this.value.length < width) {
this.screen.program.cuf();

View File

@ -200,6 +200,10 @@ var input = blessed.textbox({
top: 2
});
input.on('submit', function() {
input.clearInput();
});
screen.append(input);
var button = blessed.Button({