RFR: 8178368: Right and Center alignment of text field works incorrectly

Andy Goryachev angorya at openjdk.org
Fri Jan 6 16:50:00 UTC 2023


On Thu, 22 Dec 2022 10:33:15 GMT, Ajit Ghaisas <aghaisas at openjdk.org> wrote:

>> When Text width was more than TextField width, the logic to update `textTranslateX` in `updateCaretOff` method was causing the issue of unexpected behavior for Right and Center alignment.
>> 
>> Made changes to update `textTranslateX` in `updateCaretOff` method only when text width is less than text field width i.e `delta` is positive. 
>> For both right and center alignments, the `textTranslateX` value calculated in `updateTextPos` method will be updated without any condition so that expected behavior is achieved for all scenarios of text width relative to text field width. 
>> 
>> Added unit tests to validate LEFT, CENTER and RIGHT alignments. RIGHT and CENTER alignment tests are expected to fail without the fix provided in this PR.
>
> The proposed fix fixes the reported issue.
> 
> **Regarding the question of changing current behavior of RIGHT alignment of the TextField:**
> If the string is larger than the TextField width -
> - LEFT align should result in - Start of the text visible and end of the text hidden.
> - RIGHT align should result in - End of the text visible at the right edge of the TextField and start of the text hidden.
> 
> Right now, only the LEFT align behaves correctly.
> RIGHT align behaves correctly only if the string is smaller than the TextField width. The moment string length is larger than TextField width, it starts behaving opposite (start of the text visible and end of the text hidden.)
> I don't know whether there is some rationale for this implementation or it is a bug which went unnoticed till now.

You are right @aghaisas !
Small correction: the cursor operates correctly, the TextField just does not scroll the text so the caret remains visible.  Neither keyboard nor mouse operation (i.e. drag to select) auto-scroll the text.

For the mouse case:
- select long text
- select right or center alignment
- make the text field narrow
- click on the right end of text
- drag the mouse to the left to select
expected behavior is the text is scrolled to keep the caret always visible.

in the case of center alignment, the text does scroll when dragging to the right, but not to the left.

-------------

PR: https://git.openjdk.org/jfx/pull/980


More information about the openjfx-dev mailing list