andersonfreitas / vaadin-masked-textfield

A MaskedTextfield for Vaadin
http://vaadin.com/addon/maskedtextfield
Apache License 2.0
13 stars 24 forks source link

Cursor positioning #5

Closed oleg97 closed 13 years ago

oleg97 commented 13 years ago

Version 0.0.1 When focusing the field with an empty value and non-empty mask, starting with placeholder and containing some fixed characters, the cursor position is the first placeholder after the first fixed character sentence, not the first placeholder as expected.

E.g. we have a mask, say, like this: #-#### Initially empty field will look like this: _-____ When the control receives focus I expect the cursor to be in the first position:

_-____ ^ expected cursor position

But it is actually here:

_-____ ^ actual cursor position

Possible solution: In VMaskedTextField.java in setMask() method there is a code: ... setValue(string.toString()); updateCursor(0); } ...

updateCursor(0) calls setCursorPos(getNextPos(pos)) getNextPos(0) will return 1 in our case, and the cursor will be set in the 1 (the second) instead of 0 (the first) position. I think the problem may be fixed if we replace the updateCursor(0) call with setCursorPos(getPreviousPos(0)) as it in onFocus. It will implement the whole logic by finding the first non-fixed character (first placeholder) and position the cursor there.

Note, that the problem pops up only when we focus an empty-valued field (see onFocus event handler).

andersonfreitas commented 13 years ago

Hello, which browser are you using?

oleg97 commented 13 years ago

I'm using Firefox 3.6.11

oleg97 commented 13 years ago

oops, closed by accident, wrong button clicked. Reopen please.