1

I have a cell-based NSTableView with a text cell in a particular column. I want to provide a custom field editor so that I can do auto completion without the user pressing F5.

@implementation AutoCompleteFieldEditorTextView

-(id)init
{
    self = [super init];
    if (self)
    {
        self.focusRingType = NSFocusRingTypeDefault;
        self.fieldEditor = YES;
    }
    return self;
}

@end

This works ok except the focus ring does not exist. Even if I add:

-(void)drawFocusRingMask
{
    NSRectFill([self bounds]);
}

-(NSRect)focusRingMaskBounds
{
    return [self bounds];
}

it still does not work. How can I get the exact focus ring that appears with the default NSTextView used as a field editor in an NSTableView?

Trygve
  • 1,317
  • 10
  • 27
  • 1
    I think the cell draws the focus ring in `drawFocusRingMaskWithFrame:inView:`. It looks like there's a bug in the focus ring in a cell based table view. I tried a cell based table view in a new project and the focus ring isn't working as it should. It works ok in an old project without ARC. – Willeke Jun 25 '18 at 23:26
  • 1
    This project is cell based and no ARC. The focus ring works fine until I replace it with a subclassed NSTextView (specified with fieldEditorForView:). Do the OS-supplied one is fine, but as soon as I subclass it, it is not. – Trygve Jun 26 '18 at 00:00

1 Answers1

1

Have same problem and for solving I'm using next approach. This method overloaded in custom NSTextFieldCell which creates and return your custom NSTextView:

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
      [super drawInteriorWithFrame:cellFrame inView:controlView];

      if([controlView.window firstResponder] == self.maskTextField)
      {
         [super drawFocusRingMaskWithFrame:cellFrame
                                    inView:controlView];
      }
}

Hope this help someone in future.

toohtik
  • 1,892
  • 11
  • 27