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

Don't trigger onChange when mounting NumberWidget component #728

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

vincentfretin
Copy link
Contributor

When clicking an entity that have a position with 5 decimals, it opens the right panel, triggering props.onChange on the NumberWidget react component for position x y z, thus truncating to 3 decimals the coordinates and adding a change to the undo stack I'm currently implementing. We don't want to do any change when just mounting the react component.

@@ -38,9 +38,6 @@ export default class NumberWidget extends React.Component {
this.distance = 0;
this.onMouseDownValue = 0;
this.prevPointer = [0, 0];

this.setValue(this.props.value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setValue here was a noop, because we have if (value === this.state.value) return; in setValue, and this.state.value is already this.props.value from constructor.

@@ -131,7 +128,6 @@ export default class NumberWidget extends React.Component {

onBlur = () => {
this.setValue(parseFloat(this.input.current.value));
this.setState({ class: '' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code, this.state.class is not used in this component

@@ -38,9 +38,6 @@ export default class NumberWidget extends React.Component {
this.distance = 0;
this.onMouseDownValue = 0;
this.prevPointer = [0, 0];

this.setValue(this.props.value);
this.onBlur();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue, truncating 5 decimals to 3 decimals and triggering the props.onChange callback.

@@ -143,7 +139,6 @@ export default class NumberWidget extends React.Component {

// enter.
if (event.keyCode === 13) {
this.setValue(parseFloat(this.input.current.value));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done by the onBlur callback that's called with the blur() call below.

@@ -171,7 +166,6 @@ export default class NumberWidget extends React.Component {
onKeyDown={this.onKeyDown}
onChange={this.onChange}
onMouseDown={this.onMouseDown}
onFocus={this.onFocus}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code, this.onFocus is undefined

@vincentfretin
Copy link
Contributor Author

vincentfretin commented Jun 28, 2024

Note that when you change the value with the input field, it keeps the 5 decimals precision while using arrows but it truncates to 3 decimals on blur at the end. Only while using mouse that the precision is kept at 5 decimals because the input doesn't have the focus, so not blur.
It would probably make sense to use 3 decimals instead of 5 for TransformControls as well.

@vincentfretin
Copy link
Contributor Author

I need this PR to be merged before doing the undo position/rotation/scale PR @dmarcos

@dmarcos
Copy link
Member

dmarcos commented Jul 1, 2024

Thanks!

@dmarcos dmarcos merged commit ed577e8 into aframevr:master Jul 1, 2024
1 check passed
@vincentfretin vincentfretin deleted the fix-numberwidget branch July 1, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants