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

Numeric input does not allow non-numeric value #10457

Merged
merged 11 commits into from
Jul 10, 2024

Conversation

farmaazon
Copy link
Contributor

Pull Request Description

Fixes #9838 (see the "backlog refinement" comment there).

When someone want's to accept invalid input, it gets reverted to last recorded valid value.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • [ ] Unit tests have been written where possible.

@farmaazon farmaazon added the -gui label Jul 5, 2024
@farmaazon farmaazon self-assigned this Jul 5, 2024
@@ -1825,6 +1826,10 @@ export class MutableNumericLiteral extends NumericLiteral implements MutableAst
export interface MutableNumericLiteral extends NumericLiteral, MutableAst {}
applyMixins(MutableNumericLiteral, [MutableAst])

export function isNumericLiteral(s: string) {
return is_numeric_literal(s.trim())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about trim here. Submitting code expresisons with trailing spaces can cause issues, so effectively ignoring them in this method seems bad. If you want to trim the inputted code, do it before calling this method.

props.onUpdate({
portUpdate: { value: value.toString(), origin: props.input.portId },
portUpdate: { value: value ?? '', origin: props.input.portId },
Copy link
Contributor

Choose a reason for hiding this comment

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

undefined probably should be propagated as such, as it correctly signals a removal of an argument. Using empty string here can introduce issues by retaining unnecessary extra spaces.

@farmaazon farmaazon requested a review from Frizi July 5, 2024 13:03
@farmaazon farmaazon added the CI: Ready to merge This PR is eligible for automatic merge label Jul 5, 2024
Copy link
Contributor

@kazcw kazcw left a comment

Choose a reason for hiding this comment

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

Two general notes:

  • Should we give the user some kind of feedback before/after discarding their invalid input?
  • I think committing a previous value is odd; for example, if a user types a number, selects it, pastes something invalid (replacing the previous number), and commits, then we would commit a value that the user never attempted to commit and that has no relation to the value the user attempted to commit.

// representations.
const lastValidValue = ref<string>()
watch(editedValue, (newValue, oldValue) => {
if (newValue != oldValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The watcher will not be called if this condition is false.

@@ -91,13 +102,14 @@ const inputStyle = computed<CSSProperties>(() => {
})

function emitUpdate() {
if (valueString.value !== editedValue.value) {
emit('update:modelValue', editedValue.value)
if (props.modelValue !== lastValidValue.value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A number and a string will never be strictly equal.

const lastValidValue = ref<string>()
watch(editedValue, (newValue, oldValue) => {
if (newValue != oldValue) {
if (newValue == '' || is_numeric_literal(newValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nice to re-export is_numeric_literal from a higher level module with our JS naming convention. Whether it is an FFI call is an implementation detail.

Copy link
Contributor

@kazcw kazcw left a comment

Choose a reason for hiding this comment

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

(Previous review)

@farmaazon
Copy link
Contributor Author

  • I think committing a previous value is odd; for example, if a user types a number, selects it, pastes something invalid (replacing the previous number), and commits, then we would commit a value that the user never attempted to commit and that has no relation to the value the user attempted to commit.

I may refer to the previously committed value. I just wanted to keep user's input in case of trivial typos, like typing ' or anything else right before pressing enter, and do something simpler than trying to somehow "fix" the input myself.

Should we give the user some kind of feedback before/after discarding their invalid input?

The reverting value is sufficient feedback after IMO. As for feedback before, I feel it's a bit hard to implement in every case, because we commit on defocus, and we may be defocused with the entire window (so it would be impossible to give focus back). The only way I could think is make some highlight, but I'm not sure how to make it looking nice.

@farmaazon farmaazon requested a review from kazcw July 8, 2024 13:08
@mergify mergify bot merged commit 38bbd8b into develop Jul 10, 2024
34 checks passed
@mergify mergify bot deleted the wip/farmaazon/fix-numeric-input branch July 10, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-gui CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entering ' in a numeric input widget breaks the node
3 participants