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

[VisUi] VisTextfield + FloatDigitsOnlyFilter copy & paste missing decimal point (and minus sign) #131

Closed
mbrlabs opened this issue Feb 24, 2016 · 6 comments
Labels

Comments

@mbrlabs
Copy link

@mbrlabs mbrlabs commented Feb 24, 2016

Hi Kotcrab,
first of all thanks for that great UI extension ;)

So i noticed a little bug. I have a VisTextField, and attach a FloatDigitsOnlyFilter to it. Then i type some random floating point number and copy in that same field annother floating point number. Then the decimal point is not pasted..only the digits.
So for example if i have 0.1234 in my clipboard but there is already a floating point number in the field, the pasted float becomes 01234. The same goes for the minus sign.

As for the point, the problem lies in the acceptChar() method of the filter:
https://github.com/kotcrab/VisEditor/blob/b2ea63a045e805099ddd16778517d46d2419a637/UI/src/com/kotcrab/vis/ui/util/FloatDigitsOnlyFilter.java

If there is already a floating point number in the field this is not going to work:

public boolean acceptChar (VisTextField field, char c) {
    if (c == '.' && field.getText().contains(".") == false) return true;
    return super.acceptChar(field, c);
}

Unfortunately i don't know how this can be fixed.

@kotcrab kotcrab added bug ui labels Feb 24, 2016
@kotcrab kotcrab closed this in 0db57a0 Feb 28, 2016
@kotcrab
Copy link
Owner

@kotcrab kotcrab commented Feb 28, 2016

Thanks for reporting, I added some additional logic that ignores selected text which will be replaced when user types or pastes something.

@mbrlabs
Copy link
Author

@mbrlabs mbrlabs commented Feb 28, 2016

Great. However this introduced another bug:

  • Write a float into a TextField with the new filter attached
  • Select everything from right to left (that's important)
  • Then type something -> crash

I just created a new filter with your fix for testing this out. Here is the stacktrace:

java.lang.StringIndexOutOfBoundsException: String index out of range: -5 at java.lang.String.substring(String.java:1875) at com.mbrlabs.mundus.utils.FilterFix.acceptChar(FilterFix.java:40) at com.kotcrab.vis.ui.widget.VisTextField$TextFieldClickListener.keyTyped(VisTextField.java:1155) at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:49) at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:181) at com.badlogic.gdx.scenes.scene2d.Actor.fire(Actor.java:146) at com.badlogic.gdx.scenes.scene2d.Stage.keyTyped(Stage.java:445) at com.badlogic.gdx.InputMultiplexer.keyTyped(InputMultiplexer.java:84) at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:75) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Input.update(Lwjgl3Input.java:187) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:237) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:122) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:95) at com.mbrlabs.mundus.Main.main(Main.java:40)

That's line 38 in your FloatDigitsOnlyFilter.java:
String afterSelection = field.getText().substring(Math.max(selectionStart, cursorPos));

@kotcrab
Copy link
Owner

@kotcrab kotcrab commented Feb 28, 2016

I noticed similar crash right after I committed and made some additional changes in next commit which you probably didn't saw: aa98674. It fixes this.

@mbrlabs
Copy link
Author

@mbrlabs mbrlabs commented Feb 28, 2016

Yes, didn't see that. Thanks for the fix!

@kotcrab
Copy link
Owner

@kotcrab kotcrab commented Feb 28, 2016

No problem. Btw Mundus looks pretty nice ;)

@mbrlabs
Copy link
Author

@mbrlabs mbrlabs commented Feb 28, 2016

Thank you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.