On Thu, 4 Dec 2025 05:21:15 GMT, Prasanta Sadhukhan <[email protected]>
wrote:
>> Anass Baya has updated the pull request incrementally with one additional
>> commit since the last revision:
>>
>> The issue occurs only on Wnidows
>
> src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java line 551:
>
>> 549: if (SwingUtilities.isLeftMouseButton(e)) {
>> 550: lastClickMillis = e.getWhen();
>> 551: dragActive = true;
>
> 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?
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28582#discussion_r2589211078