Skip to content

Double clicking on an empty TextField crashes the application #172

Description

@LichtHund

The crash happens due to the caret wanting to move left when there is nothing.
I was going to PR it but because it can be fixed in multiple places and I wasn't sure which place would be best so, I thought I should make an issue first.

The error is:

Exception in thread "kool-main-backend-thread" java.lang.IllegalArgumentException: max (-1) is smaller than min (0) 
	at de.fabmax.kool.util.TextCaretNavigation.moveWordLeft(TextCaretNavigation.kt:62)
	at de.fabmax.kool.util.EditableText.moveWordLeft(EditableText.kt:51)
	at de.fabmax.kool.util.EditableText.moveCaret(EditableText.kt:42)
	at de.fabmax.kool.modules.ui2.TextFieldNode.onClick(TextField.kt:263)
	at de.fabmax.kool.modules.ui2.UiModifierKt$onClick$1.invoke(UiModifier.kt:298)
	at de.fabmax.kool.modules.ui2.UiModifierKt$onClick$1.invoke(UiModifier.kt:298)
	at de.fabmax.kool.modules.ui2.UiSurface$UiInputHandler.invokePointerCallback(UiSurface.kt:557)
	at de.fabmax.kool.modules.ui2.UiSurface$UiInputHandler.invokePointerCallback$default(UiSurface.kt:545)

It can be fixed by add && editText.text.isNotEmpty() to the double click condition in the TextField#onClick, or in TextCaretNavigation#moveWordLeft adding if (text.isEmpty()) return 0 which probably makes more sense since the other functions above it already do the same check.
Let me know which one you prefer and I am happy to PR too!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions