-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8319880: JTextField text selection doesn't stop if ended during loss of window focus #28582
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back abaya! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@anass-baya The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
|
||
| robot.delay(500); | ||
|
|
||
| Point location = textField.getLocationOnScreen(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These calls are still need to happen on EDT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OKay, thanks
test/jdk/javax/swing/JTextField/TextSelectionFocusLoss/TextSelectionFocusLoss.java
Outdated
Show resolved
Hide resolved
| @@ -539,6 +547,8 @@ public void mousePressed(MouseEvent e) { | |||
| int nclicks = SwingUtilities2.getAdjustedClickCount(getComponent(), e); | |||
|
|
|||
| if (SwingUtilities.isLeftMouseButton(e)) { | |||
| lastClickMillis = e.getWhen(); | |||
| dragActive = true; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we set dragActive here? it's just mousePressed, in which case all mousePress event will have dragActive set.
I guess it should be set in mouseDragged and reset in mouseReleased, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that when we start selecting text and then switch to another window, our window loses focus. After losing focus, we no longer receive mouse events. So when we release the mouse button in the other window and then switch back, our window thinks the drag is still happening because it never received the mouse-release event.
To fix this, we added logic to stop the drag as soon as we lose focus. And when we regain focus, since we don’t know whether the mouse was released or not, we require a new mouse-press before allowing dragging again. We also added logic to ignore outdated drag events: any drag event that happened before the last mouse-press is considered outdated and is ignored.
So now the behavior matches what we see in native apps like Notepad. @aivanov-jdk asked to check how a native Windows app behaves in this situation and to make our behavior consistent with that.
This logic does not affect the behavior on macOS.
Analysis :
The issue is that on Win32, if the window is not active, we dont receive mouse events because we release the capture
So the problem is the following:
We start selecting text from the right to the extreme left.
Then we switch to another window( the window lose focus ), and we release the mouse
But when we return to the window, the caret drag is still active and does not stop. as the window did not recieved the mouse release event
Proposed fix:
In the Caret class, we added a logic to ignore the drag if the focus was lost due to window switching unless a new mouse press happens
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28582/head:pull/28582$ git checkout pull/28582Update a local copy of the PR:
$ git checkout pull/28582$ git pull https://git.openjdk.org/jdk.git pull/28582/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28582View PR using the GUI difftool:
$ git pr show -t 28582Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28582.diff
Using Webrev
Link to Webrev Comment