From 5212bd428e425c92e57090a0b0cba5ba920c0f98 Mon Sep 17 00:00:00 2001 From: AARON WELLES Date: Wed, 26 Jun 2019 23:18:41 -0400 Subject: [PATCH] Attempt at listen fix checks dom.isactive & allows displayUpdate(force), set true for by default for setValue fixes isactive problems allows drag events, and re-added key up/down --- src/dat/controllers/Controller.js | 5 +++-- src/dat/controllers/NumberControllerBox.js | 26 ++++++++++++++++------ src/dat/controllers/OptionController.js | 10 ++++----- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/dat/controllers/Controller.js b/src/dat/controllers/Controller.js index b65c774..2c9dd17 100644 --- a/src/dat/controllers/Controller.js +++ b/src/dat/controllers/Controller.js @@ -17,6 +17,7 @@ * @param {Object} object The object to be manipulated * @param {string} property The name of the property to be manipulated */ + class Controller { constructor(object, property) { this.initialValue = object[property]; @@ -92,7 +93,7 @@ class Controller { this.__onChange.call(this, newValue); } - this.updateDisplay(); + this.updateDisplay(true); return this; } @@ -110,7 +111,7 @@ class Controller { * with the object's current value. * @returns {Controller} this */ - updateDisplay() { + updateDisplay(force) { return this; } diff --git a/src/dat/controllers/NumberControllerBox.js b/src/dat/controllers/NumberControllerBox.js index 462ebf2..e383938 100644 --- a/src/dat/controllers/NumberControllerBox.js +++ b/src/dat/controllers/NumberControllerBox.js @@ -94,11 +94,22 @@ class NumberControllerBox extends NumberController { dom.bind(this.__input, 'mousedown', onMouseDown); dom.bind(this.__input, 'keydown', function(e) { // When pressing enter, you can be as precise as you want. - if (e.keyCode === 13) { - _this.__truncationSuspended = true; - this.blur(); - _this.__truncationSuspended = false; - onFinish(); + const step = _this.__step || 1; + switch (e.keyCode) { + case 13: + _this.__truncationSuspended = true; + this.blur(); + _this.__truncationSuspended = false; + onFinish(); + break; + case 38: + var newVal = _this.getValue() + step; + _this.setValue(newVal); + break; + case 40: // down + var newVal = _this.getValue() - step; + _this.setValue(newVal); + break; } }); @@ -107,10 +118,11 @@ class NumberControllerBox extends NumberController { this.domElement.appendChild(this.__input); } - updateDisplay() { + updateDisplay(force) { + if (!force && dom.isActive(this.__input)) return this; this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision); return super.updateDisplay(); } } -export default NumberControllerBox; +export default NumberControllerBox; \ No newline at end of file diff --git a/src/dat/controllers/OptionController.js b/src/dat/controllers/OptionController.js index b349031..f5750c0 100644 --- a/src/dat/controllers/OptionController.js +++ b/src/dat/controllers/OptionController.js @@ -24,7 +24,7 @@ import common from '../utils/common'; * @param {Object} object The object to be manipulated * @param {string} property The name of the property to be manipulated * @param {Object|string[]} options A map of labels to acceptable values, or - * a list of acceptable string values. +* a list of acceptable string values. */ class OptionController extends Controller { constructor(object, property, opts) { @@ -75,11 +75,11 @@ class OptionController extends Controller { return toReturn; } - updateDisplay() { - if (dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update + updateDisplay(force) { + if (!force && dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update this.__select.value = this.getValue(); - return super.updateDisplay(); + return super.updateDisplay(force); } } -export default OptionController; +export default OptionController; \ No newline at end of file