Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » selection in multiline Text widget(Unexpected behavior when trying to select text in a textarea which does not have input focus)
selection in multiline Text widget [message #1857356] Wed, 01 February 2023 14:09 Go to next message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
Hi,

we are trying to find a solution for a customer-reported "bug", which can also be reproduced in the Eclipse RAP Controls Demo:

The user reporting this wants to use the mouse to select text from a textarea which contains multiple lines with the vertical scrollbar enabled.
Whenever the selection (caret position) is scrolled out of view and the text widget does not have input focus, the following will happen:

When the user clicks in the textarea to start a text selection, the previous selection position is scrolled into view (on Edge / Chrome browsers, Firefox behaves differently), which causes an unexpected area of the text to be selected. We were able to track this down to a call on _inputElement.focus(), i.e. the current selection is scrolled into view when the textarea is focused as part of the handling of the mousedown event.

In order to reproduce this, you can set the BORDER, WRAP and MULTI properties on the Text RAP Controls demo page, set the size of the textarea to 200x100 and paste a long text (e.g. "Lorem ipsum").
Now, after selecting some text in that text area, either scroll the selected portion out of view and focus another control on the page or focus some other control on the page and then use the mouse wheel to scroll the selected portion of the text out of the visible area.
When you now try to click in the text field, you will notice, that the text will change upon mousedown and you do not hit/select the portion of the text you would expect.

Can you think of a way to apply the selection (based on mouse cursor) BEFORE textarea.focus() is called?

Thank you and best regards,
Gunnar Adams


Re: selection in multiline Text widget [message #1857367 is a reply to message #1857356] Thu, 02 February 2023 08:10 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,

please file an issue at https://github.com/eclipse-rap/org.eclipse.rap/issues and we will investigate the cause.

Thanks,
Ivan
Re: selection in multiline Text widget [message #1857368 is a reply to message #1857356] Thu, 02 February 2023 08:39 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
...ok... There is a difference if you focus the Text field back with mouse (click on scrollbar) or TAB. When the TAB is used the selection is preserved and revealed. When mouse is used the selection is reset to the zero, starting from the previous first selected character and also revealed. In other words, when mouse is used the selection is removed. Is this exactly what you observe?

Best regards,
Ivan
Re: selection in multiline Text widget [message #1857369 is a reply to message #1857368] Thu, 02 February 2023 08:53 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
... and there is a specific code [1] not to apply selection on focus if it's done by mouse. This behavior has been introduced 10 years ago and I don't remember the reason.

[1] https://github.com/eclipse-rap/org.eclipse.rap/blob/main/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/BasicText.js#L502

[Updated on: Thu, 02 February 2023 08:57]

Report message to a moderator

Re: selection in multiline Text widget [message #1857372 is a reply to message #1857368] Thu, 02 February 2023 11:12 Go to previous messageGo to next message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
Hi Ivan,
thank you for the quick response.
Yes, activation via keyboard navigation works as expected.
The problem reported by our users only occurs when the mouse is used to apply a "selection" in an up to that point not yet focused textarea.

Imagine, that you are searching in a long text for a portion of text that you want to copy to the clipboard.
For this search it isn't required that the field has the input focus. Users can use the mouse wheel to scroll the text. When they find the text they need, they will click into the field. and expect that the text caret and/or the selection will be put in that position.
Because the browser scrolls the (previous) selection into view when the textarea is focused, users will end up with a wrong selection position.
In the above description I use "selection" as synonymous for both a caret position and an actual non-empty selection (i.e. the length of the selection does not matter).

I do not know, if it is even possible to determine and store the desired selection position (determined from the mouse position on mousedown) prior to the textarea getting the focus. I think, though, that the browser should in the default behavior of a mouse click (or mousedown) on a textarea first apply the selection and then "focus" the textarea (if it wasn't already focused). If that would be the case, the explicit _inputElement.focus() call on mousedown in the RWT framework might prevent that default behaviour.

Best regards,
Gunnar
Re: selection in multiline Text widget [message #1857373 is a reply to message #1857369] Thu, 02 February 2023 11:19 Go to previous message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
as to the code in

https://github.com/eclipse-rap/org.eclipse.rap/blob/main/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/BasicText.js#L502

I imagine, that this is actually correct, because when you click into a text, the selection set on the widget should not "win". Instead, the position at the mouse cursor should end up as the selection.
This works, unless the previous selection has been scrolled out of view (causing a movement of the scrollbar). It also works in Firefox browsers.
It might be that only Chrome-based browsers scroll the selection into view when the textarea's focus() method is called.

Best regards,
Gunnar
Previous Topic:How to work with RAP in 2023 ?
Next Topic:Text control not wide enough in italic font
Goto Forum:
  


Current Time: Wed Jun 19 21:24:18 GMT 2024

Powered by FUDForum. Page generated in 0.03524 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top