-1

I'd like to make NSTableView behave more like a traditional text editor, where hovering over the editable text area immediately shows the IBeamCursor without having to click or double-click into the table cell first.

(I tried asking for a solution which changes the general behavior of the table view to achieve all of these things at once (How to make an NSTableView behave more like a text editor?), but such a solution doesn't seem to exist.)

So the question is now, where would be an appropriate place to put the code to change the mouse cursor? Or maybe, is there a way forward the mouse events to the underlying text field / text cell so that the regular cursor behavior is triggered that occurs with a single NSTextField outside of an NSTableView?

I'd prefer a solution for a view-based table view (as I want to put a custom view into one of the table columns), but solutions for a cell-based table view are also appreciated if there is no easy way with view-based ones.

tajmahal
  • 1,665
  • 3
  • 16
  • 29
  • 1
    Have you tried adding a tracking area to the text field? – Willeke May 12 '23 at 12:12
  • No. What would be the best place for adding that? Currently, the text field is created in IB. – tajmahal May 12 '23 at 14:40
  • 1
    A subclass of `NSTextField`. – Willeke May 12 '23 at 14:59
  • While looking into how to add a tracking area to an `NSTextField` subclass, I stumbled about the following SO question, which I hadn't seen before: https://stackoverflow.com/questions/12079531/cant-change-the-mouse-cursor-of-a-nstextfield The first answer solves my problem in a super easy way, without actually requiring to manually add a tracking area. So thanks for pointing me in the right direction! :) – tajmahal May 12 '23 at 15:50

1 Answers1

1

So turns out the answer is as simple as adding the following to an NSTextField subclass:

- (void)resetCursorRects {
    [self addCursorRect:[self bounds] cursor:[NSCursor IBeamCursor]];
}

Based on the following answer referring to a plain NSTextField, which happens to work for one embedded in a view-based NSTableView as well: Can't change the mouse cursor of a NSTextField (which I found through @Willeke's hint of subclassing the NSTextField)

tajmahal
  • 1,665
  • 3
  • 16
  • 29