Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt at listen fix #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/dat/controllers/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -92,7 +93,7 @@ class Controller {
this.__onChange.call(this, newValue);
}

this.updateDisplay();
this.updateDisplay(true);
return this;
}

Expand All @@ -110,7 +111,7 @@ class Controller {
* with the object's current value.
* @returns {Controller} this
*/
updateDisplay() {
updateDisplay(force) {
return this;
}

Expand Down
26 changes: 19 additions & 7 deletions src/dat/controllers/NumberControllerBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand All @@ -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;
10 changes: 5 additions & 5 deletions src/dat/controllers/OptionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;