NSCollectionView's 'selection box' freezes if you right-click during dragging

So in NSCollectionView I left click the background and start dragging to make the 'selection box' (is that what we call it?)

I have a mouse with separate left and right click buttons (i.e., not an Apple Magic Mouse). Now if I accidentally hit the right click while I'm still dragging the selection box..... the right click context menu shows up in the middle of mouse dragging and the selection box freezes on screen.

Besides the visual disruption this sometimes results in weird behavior. Sometimes mouse clicks stop responding for awhile in the window and I gotta click around a bunch of times until I guess the run loop "unclogs."

I'm able to reproduce in Finder Icon view so it isn't just me.

Steps to Reproduce:

  1. A mouse with separate buttons for left and right click.
  2. Open Finder window in icon view.
  3. Left click the background and start dragging to make the gray selection box.
  4. While dragging the mouse as you are selecting click right-click in the middle of the drag.
  5. The selection box freezes on screen.

Expected Behavior: -Right click event and left mouse drag event normally shouldn't overlap. If left mouse is being dragged the right click event should be blocked.

Let me know if this is Feedback worthy.

This seems to avoid the issue:

-(void)rightMouseDown:(NSEvent*)theEvent
{
    if ((NSEvent.pressedMouseButtons & (1 << 0)) != 0)
    {
        // Not at the same time, dog.
        return;
    }
 
    [super rightMouseDown:theEvent];
}
Accepted Answer

This seems to avoid the issue:

-(void)rightMouseDown:(NSEvent*)theEvent
{
    if ((NSEvent.pressedMouseButtons & (1 << 0)) != 0)
    {
        // Not at the same time, dog.
        return;
    }
 
    [super rightMouseDown:theEvent];
}

Thanks for the post, so if I understand well you got the same behavior with Finder than you code?

When you left-click and drag to create the experience, AppKit often enters a localized event-tracking loop waiting for a mouseUp event to finalize the selection and remove the gray box. Do you see that?

When you right-click, AppKit immediately summons an NSMenu. It never receives the mouseUp event it was waiting for. As a result, maybe is what you are seeing?

Since you reproduced this in Finder, it is highly recommended to file this via Feedback Assistant.

Once you open the bug report, please post the FB number here for my reference.

If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

Albert
  Worldwide Developer Relations.

I filed FB22716998

[@Macho Man Randy Savage](https://developer.apple.com/forums/profile/Macho Man Randy Savage) Thanks so much for doing that, the bug description and screen recording are great as always your bug as clean and can be sent to the correct team quickly.

For more details on when you'll see updates to your report, please see What to expect after submission.

Albert
  Worldwide Developer Relations.

No problem.

I also just noticed if you do the selection quite rapidly the selection box can also get stuck (no right click required).

Seems to happen when collection view is grouped though I'm not sure exactly if that has anything to do with it (so in Finder "Use Groups" with section headers). Also if you mouse drag while you are doing the selection box outside the collection view (to the point where your cursor extends into the sidebar in Finder) things sometimes stop working.

What things stop working? Mouse clicks. The collection view temporarily stops responding to mouse clicks. Using the arrow keys to move the selection 'fixes it' then mouse clicks start working again.

My app uses an NSSplitView and has sidebar and a collection view so my app is impacted the same way. My hope is because Finder is impacted they may fix. Fingers crossed.

In my app when this mouse clicking problem happens I am getting -mouseDown: in my NSCollectionView subclass (and calling super) but the collection view just doesn't modify the selection when you click on items nor does it deselect when you click on the background.

NSCollectionView's 'selection box' freezes if you right-click during dragging
 
 
Q