title: NSOutlineView: sometimes a row is not editable (just beeps)
body: <p>I have a view-based <code>NSOutlineView</code> configured with a dataSource and delegate. It consists of two columns a custom <code>NSTableCellView</code> class. </p>
  
  <p>Entries in the outline view are editable by selecting a row and pressing the <code>Return</code> key. Everything is set up according the docs and works fine most of the time.</p>
  
  <p>However, sometimes when I press <code>Return</code> while a row is selected, the cell's text field does not enter into edit mode. It just beeps.</p>
  
  <p>I can still enter edit mode by "long clicking" on the text field. For some reason, the <code>Return</code> key event is sometimes handled differently by the outline view. </p>
  
  <p>I captured two stacktraces:</p>
  
  <p><strong>#1 Working as expected:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/X5EwW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X5EwW.png" alt="working"></a></p>
  
  <p>You can see that from <code>keyDown()</code> the event eventually makes the cell's text field the first responder.</p>
  
  <p><strong>#2 Beeping</strong></p>
  
  <p><a href="https://i.stack.imgur.com/7IKni.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7IKni.png" alt="beep"></a></p>
  
  <p>I put a breakpoint at <code>NSBeep</code> and you can see that the key even takes a different path this time.</p>
  
  <p>I suspect that maybe the internal state of the outline view or underlying <code>NSTableView</code> is mixed up... </p>
  
  <p>How can I troubleshoot this from here? Which steps does the outline view take to determine if a row can be edited after the Return key was pressed?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I did some more debugging (thanks to @Willeke for the tip about the breakpoint). I managed to tack it down to this:</p>
  
  <ul>
  <li>Return key is pressed</li>
  <li><code>NSOutlineView.keydown</code></li>
  <li>...</li>
  <li><code>NSOutlineView.selectedRow</code>
  
  <ul>
  <li>outline view checks which row is selected</li>
  </ul></li>
  <li><code>NSOutlineView.rowView(atRow row: Int, makeIfNecessary: Bool)</code>
  
  <ul>
  <li>outline view retrieves the selected row view</li>
  </ul></li>
  <li><code>NSTableRowView.nextValidKeyView</code>
  
  <ul>
  <li>current row view is asked for the next valid key view</li>
  </ul></li>
  <li><code>NSTableRowView.nextKeyView</code> 
  
  <ul>
  <li>Now this returns sometimes <code>nil</code> and the app just beeps. Most of the time it returns the <code>NSTableCellView</code> for that row containing the <code>NSTextField</code> that is then made first responder and hence editable.</li>
  </ul></li>
  </ul>
  
  <p>Now the question is why is the next key view <code>nil</code> sometimes? I click on the outline view's row so it does have the focus/is selected...</p>