NSTextView not changing font size or colour from NSFontPanel

386 Views Asked by At

I created a basic NSTextView, I selected the following options in Interface Builder:

  • Editable
  • Selectable
  • Field Editor
  • Rich Text
  • Undo
  • Graphics
  • Non-contiguous Layout
  • Font Panel
  • Ruler
  • Inspector Bar

I set the NSViewController to be the delegate of the NSTextView and the only other custom thing I've done for this NSTextView is to enable inserting tabs and new lines (by accepting First responder):

    func textView(_ textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {

    if commandSelector == #selector(insertNewline(_:)) {
        textView.insertNewlineIgnoringFieldEditor(self)
        return true
    } else if commandSelector == #selector(insertTab(_:)) {
        textView.insertTabIgnoringFieldEditor(self)
        return true
    } //else if commandSelector == #selector(changeColor(_:)) {
        //textView.setTextColor(NSFontPanel.colo, range: <#T##NSRange#>)
    //}

    return false

}

When I try to use the commands from the Font Panel + Inspector Bar, All the commands work fine except changing Font size or colour, is there anything that could be wrong? Or do I need to do extra binding/delegates, etc for this to work?

It is strange because if I change the Font itself (of a selected text) or the weight, it works fine (no coding was needed).

Update

I've found the root of the problem causing this. I'm displaying the TextView in a ViewController that is displayed using a Modal segue. If I change from Modal to Show, the size and colour work fine. There's also no need for the extra commands for insert new line and tab.

Is there any reason why this is the case? Is there any customisation that should be done to the segue to avoid this? And, why is the view controller presentation affecting the behaviour of the font panel?

1

There are 1 best solutions below

0
On

NSFontPanel has a 'worksWhenModal' property which sounds as if it might be set to 'false'.

A Boolean that indicates whether the receiver allows fonts to be changed in modal windows and panels. Documentation: