Skip to content

Commit

Permalink
Merge listen fix from dataarts#246.
Browse files Browse the repository at this point in the history
  • Loading branch information
superkelvint committed Mar 29, 2022
1 parent 1d76188 commit 36ca84e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dat/controllers/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Controller {
this.__onChange.call(this, newValue);
}

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

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

Expand Down
28 changes: 21 additions & 7 deletions src/dat/controllers/NumberControllerBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,24 @@ 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:
const newVal1 = _this.getValue() + step;
_this.setValue(newVal1);
break;
case 40: // down
const newVal2 = _this.getValue() - step;
_this.setValue(newVal2);
break;
default:
break;
}
});

Expand All @@ -107,9 +120,10 @@ 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();
return super.updateDisplay(force);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/dat/controllers/OptionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ 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);
}
}

Expand Down

0 comments on commit 36ca84e

Please sign in to comment.