Skip to content

Wrong formatting when letters mask used [___] #49

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

Closed
kvrus opened this issue Apr 13, 2018 · 5 comments
Closed

Wrong formatting when letters mask used [___] #49

kvrus opened this issue Apr 13, 2018 · 5 comments

Comments

@kvrus
Copy link

kvrus commented Apr 13, 2018

It works well for digits, but for letters, there is one issue:
For example mask is [____]
when you type the second character it will turn cursor to the start of the line, so new chars will appear from zero position.

This is because isDeletion defined in wrong way. I suggest using this method instead
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
isDeletion = p2 > p3
this.listener?.beforeTextChanged(p0, p1, p2, p3)
}

I can't make PR, so will wait for the fix)))

@taflanidi taflanidi self-assigned this Apr 13, 2018
@taflanidi
Copy link
Collaborator

Hi @kvrus,
Thanks for your report.

You are making a surprisingly big statement there without addressing the root causes.

First of all, what makes you think you understood isDeletion correctly?
Second, did you read provided Known issues section carefully? Especially the InputMask vs. autocorrection part.

Now please, kindly set inputType of your EditText to textVisiblePassword and come back with the results, thank you.

@yatsinar
Copy link

Oh, I had to override this method almost exactly as above.
I had InputType.TYPE_DATETIME_VARIATION_DATE and custom DigitsKeyListener set up programatically but there was issues with jumping cursor.
Library code looks like this:

    override fun onTextChanged(text: CharSequence, cursorPosition: Int, before: Int, count: Int) {
        val isDeletion: Boolean = before > 0
        //other code

Problem is before is just the number of replaced characters, but there is also a count.
When count is zero - the case is really isDeletion. But when count > 0 and before > 0 - that's insertion, not deletion.

Following overriding resolved all the cursor issues:

    override fun onTextChanged(text: CharSequence, cursorPosition: Int, before: Int, count: Int) {
        //DO NOT CALL SUPER - this is purposely overwritten onTextChanged implementation
        val isDeletion: Boolean = before > 0 && count == 0
        //other code is the same as in library

That was quite ad hoc solution, but you definitely could look into that line closer and probably will be able to resolve one of "Known issues".

@taflanidi
Copy link
Collaborator

taflanidi commented Apr 14, 2018

Hi @yatsinar!
Thanks for your comment.

Oh, I had to override this method almost exactly as above.

To be honest, your solution sounds almost nothing like the proposal above.
Moreover, it resembles the logic used in our iOS library counterpart , verbatim.

Which makes it a perfect candidate for a pull request.
Would you like to submit your fix to our library?

P.s. When count > 0 and before > 0 — that's a replacement, not an insertion. You replace selected text with a button press or by pasting from the clipboard.

@yatsinar
Copy link

Yeah, sure, replacement)

@taflanidi
Copy link
Collaborator

@yatsinar, 2.3.1 has been published.
Thanks for your contribution!

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

No branches or pull requests

3 participants