Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Typing separator deletes existing text in MaskedInput #6315

@TomJGooding

Description

@TomJGooding

While trying to fix some bugs in the MaskedInput, I discovered that typing a separator is expected to jump to the next separator, skipping over any empty positions.

For example, notice the jumps in the example below after typing a digit then a separator:

masked-input-separator-jump

Example code
from textual.app import App, ComposeResult
from textual.widgets import MaskedInput


class MaskedInputApp(App):
    def compose(self) -> ComposeResult:
        yield MaskedInput(
            template="9999-9999-9999-9999;_",
        )


if __name__ == "__main__":
    app = MaskedInputApp()
    app.run()

This behaviour doesn't appear to be documented anywhere (or covered in tests), but it seems to emulate masked inputs in Qt, which the Textual widget is based on.

The problem is that the current implementation will also delete any existing text when jumping to the next separator.

For example, pressing the right arrow then the separator key with existing text:

Image

Unfortunately this looks like another bug in the MaskedInput, especially when compared to the Qt widget.

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