MouseMoved notification in NSTextView produces message "Shared items array is empty"
Asked Answered
C

2

6

I am using a custom mouseMove event in NSTextView to set the cursor to a pointer when it's outside the content insets. When it's inside the editable area, I'm calling [super mouseMove]:

- (void)mouseMoved:(NSEvent*)event {
    NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
    
    if ((point.x > self.textContainerInset.width &&
         point.x < self.frame.size.width - self.textContainerInset.width)
    ) {
        [super mouseMoved:event];
    } else if (point.x > 10) {
        [NSCursor.arrowCursor set];
    }
}

When selecting a line break in my text (meaning the empty part at the end of a line) and hovering mouse over the selection, [super mouseMoved:event] produces the following message on every pixel the mouse moves:

Appname[29357:853497] [Framework] Shared items array is empty
Appname[29357:853497] [Framework] No shared items can be accessed

I am confused why this happens and what might be the cause?

EDIT: This seems to happen even without subclassing NSTextView. It might be a bug in macOS Catalina. For me, it doesn't seem to cause any other problems.

Casia answered 3/11, 2020 at 11:58 Comment(7)
Does the example project HoverTest produce the messages?Anatole
Yes. It sometimes requires some cmd-tabbing, but it produces the exact messages, at least for me on 10.15.4.Casia
In MainMenu.xib the class of the text view isn't TextView and the textView outlet of AppDelegate isn't connected. Is your code executed?Anatole
Uh, I managed to save a copy into Dropbox and not the intended version. However, the same effect seems to happen even without the custom TextView class or the code, so I'm guessing it's a NSTextView bug in the latest macOS.Casia
I have this exact problem and this question is the only thing I found with the "No shared items can be accessed" search term. Have you managed to find the issue?Odonnell
Unfortunately not. I'm guessing it's a system bug/feature, and doesn't seem to cause any other problems besides flooding the log full of alerts.Casia
I am facing this same bug too on MacOS 10.15.4 Catalina. And this seems to be causing my app to unable to read the UserDefaults.Villatoro
M
0

I found a solution. It conflicts with the standard recommendation for subclassing. But as far as I can tell, it introduces no unwanted behavior. Subclass your NSTextView and override this method (yes, without calling the superclass, which is the part that makes the solution work, sigh):

override func mouseMoved(with event: NSEvent) {} // swift

Meliamelic answered 13/2, 2023 at 7:25 Comment(0)
G
0

In my case, I have to call addTrackingArea method to enable mouse tracking, and the console stopped wanring No shared items can be accessed as well.

eg:

class TrackableImageView: NSImageView {

override func mouseEntered(with event: NSEvent) {
    super.mouseEntered(with: event)
}

override func mouseExited(with event: NSEvent) {
    super.mouseExited(with: event)
}

override func viewDidMoveToWindow() {
    super.viewDidMoveToWindow()
    addTrackingArea(.init(rect: frame, options: [.mouseEnteredAndExited, .activeInKeyWindow], owner: self))
     
}

}

Galloping answered 9/1 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.