From 3ef5cfe8463de28d7bfe053b12e907a5405a8888 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sun, 24 Mar 2013 18:35:16 +0100 Subject: [PATCH 1/2] Fixed: Infinite loop when a first responder has a nil superview This bug appears only if a table view have been added to the window. CPTableView observes first responder changes and moves up in the view hierarchy to determine the edited data view. If for some reason, a superview in the hierarchy was nil, we entered an infinite loop. This commit adds guards to the recursive method that searches the data view. Also added an early return when the fr changes to a view outside the table. Fixes #1875 --- AppKit/CPTableView.j | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 308978fe4..0084f46ba 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1981,11 +1981,12 @@ NOT YET IMPLEMENTED return -1; var cellView = aView, - contentView = [[self window] contentView]; + contentView = [[self window] contentView], + max_rec = 100; - while (1) + while (max_rec--) { - if (cellView == contentView) + if (!cellView || cellView === contentView) { return -1; } @@ -5048,6 +5049,13 @@ Your delegate can implement this method to avoid subclassing the tableview to ad { var responder = [[self window] firstResponder]; + if (!responder || ![responder isDescendantOf:self]) + { + _editingRow = CPNotFound; + _editingColumn = CPNotFound; + return; + } + _editingRow = [self rowForView:responder]; _editingColumn = [self columnForView:responder]; From a9ec90713e735460b3aac6fd891adace6512f762 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sun, 24 Mar 2013 20:33:22 +0100 Subject: [PATCH 2/2] The FR can be a window, don't check if it's inside a table. --- AppKit/CPTableView.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index f240220ff..e03b78802 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -5094,7 +5094,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad { var responder = [[self window] firstResponder]; - if (!responder || ![responder isDescendantOf:self]) + if (![responder isKindOfClass:[CPView class]] || ![responder isDescendantOf:self]) { _editingRow = CPNotFound; _editingColumn = CPNotFound;