diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/form/FocusElement.js | 9 | ||||
-rw-r--r-- | ui/form/Form.js | 26 |
2 files changed, 29 insertions, 6 deletions
diff --git a/ui/form/FocusElement.js b/ui/form/FocusElement.js index 18f13bf..79a8afc 100644 --- a/ui/form/FocusElement.js +++ b/ui/form/FocusElement.js @@ -25,11 +25,18 @@ module.exports = class FocusElement extends DisplayElement { this.isFocused = false } + get selectable() { + // Should be overridden if you want to make the element unselectable + // (according to particular conditions). + + return true + } + keyPressed(keyBuf) { // Do something with a buffer containing the key pressed (that is, // telnet data sent). Should be overridden in subclasses. // - // Keyboard characters are sent as a buffer in the form of + // Arrow keys are sent as a buffer in the form of // ESC[# where # is A, B, C or D. See more here: // http://stackoverflow.com/a/11432632/4633828 } diff --git a/ui/form/Form.js b/ui/form/Form.js index ce064aa..e5d756a 100644 --- a/ui/form/Form.js +++ b/ui/form/Form.js @@ -59,6 +59,10 @@ module.exports = class Form extends FocusElement { } } + get selectable() { + return this.inputs.some(inp => inp.selectable) + } + updateSelectedElement() { if (this.root.select) { this.root.select(this.inputs[this.curIndex]) @@ -66,16 +70,23 @@ module.exports = class Form extends FocusElement { } previousInput() { - this.curIndex = (this.curIndex - 1) - if (this.curIndex < 0) { - this.curIndex = (this.inputs.length - 1) - } + // TODO: Forms currently assume there is at least one selectable input, + // but this isn't necessarily always the case. + do { + this.curIndex = (this.curIndex - 1) + if (this.curIndex < 0) { + this.curIndex = (this.inputs.length - 1) + } + } while (!this.inputs[this.curIndex].selectable) this.updateSelectedElement() } nextInput() { - this.curIndex = (this.curIndex + 1) % this.inputs.length + // TODO: See previousInput + do { + this.curIndex = (this.curIndex + 1) % this.inputs.length + } while (!this.inputs[this.curIndex].selectable) this.updateSelectedElement() } @@ -83,6 +94,11 @@ module.exports = class Form extends FocusElement { firstInput(selectForm = true) { this.curIndex = 0 + // TODO: See previousInput + if (!this.inputs[this.curIndex].selectable) { + this.nextInput() + } + if (selectForm || ( this.root.isChildOrSelfSelected && this.root.isChildOrSelfSelected(this) )) { |