From 718ac0a51496654635b6ca926c2573c6331ee8d3 Mon Sep 17 00:00:00 2001 From: felixlinker Date: Sat, 13 Oct 2018 22:29:12 +0100 Subject: [PATCH] Enhance number editing --- src/app/components/Modification.jsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/components/Modification.jsx b/src/app/components/Modification.jsx index b2979bb7..c33381f6 100644 --- a/src/app/components/Modification.jsx +++ b/src/app/components/Modification.jsx @@ -39,10 +39,24 @@ export default class Modification extends TranslatedComponent { * in a value by hand */ _updateValue(value) { - let { m, name, ship } = this.props; - value = Math.max(Math.min(value, 50000), -50000); - ship.setModification(m, name, value, true, true); this.setState({ value }); + let reCast = String(Number(value)); + if (reCast.endsWith(value) || reCast.startsWith(value)) { + let { m, name, ship } = this.props; + value = Math.max(Math.min(value, 50000), -50000); + ship.setModification(m, name, value, true, true); + } + } + + /** + * Triggered when a key is pressed down with focus on the number editor. + * @param {SyntheticEvent} event Key down event + */ + _keyDown(event) { + if (event.key == 'Enter') { + this._updateFinished(); + } + this.props.onKeyDown(event); } /** @@ -91,7 +105,7 @@ export default class Modification extends TranslatedComponent { {this.props.editable ? :