From 0f4b60314bd5d4898eb28d674ae2a0435f55e264 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 18 Jul 2013 22:49:06 -0500 Subject: [PATCH] allow tabbing from textboxes in forms. --- lib/widget.js | 25 ++++++++++++++++--------- test/widget.js | 4 ++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 4c96f52..1ce01d6 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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(); diff --git a/test/widget.js b/test/widget.js index afb4b8f..b75530c 100644 --- a/test/widget.js +++ b/test/widget.js @@ -200,6 +200,10 @@ var input = blessed.textbox({ top: 2 }); +input.on('submit', function() { + input.clearInput(); +}); + screen.append(input); var button = blessed.Button({