Skip to content

Commit fe050df

Browse files
committed
Attempt at fixing a crash when trying to open the field editor sheet and Accessibility Services are enabled and a certain other Application is running (issue #2220)
1 parent 6f00eaa commit fe050df

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Diff for: Source/SPCustomQuery.m

+9-4
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,12 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn
24412441

24422442
// Check if the field can identified bijectively
24432443
if ( aTableView == customQueryView ) {
2444+
2445+
// Nothing is editable while the field editor is running.
2446+
// This guards against a special case where accessibility services might
2447+
// check if a table field is editable while the sheet is running.
2448+
if (fieldEditor) return NO;
2449+
24442450
NSDictionary *columnDefinition = [cqColumnDefinition objectAtIndex:[[aTableColumn identifier] integerValue]];
24452451

24462452
// Check if current field is a blob
@@ -2450,7 +2456,6 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn
24502456
// Open the editing sheet if required
24512457
if ([customQueryView shouldUseFieldEditorForRow:rowIndex column:[[aTableColumn identifier] integerValue] checkWithLock:NULL])
24522458
{
2453-
if (fieldEditor) SPClear(fieldEditor);
24542459
fieldEditor = [[SPFieldEditorController alloc] init];
24552460

24562461
// Remember edited row for reselecting and setting the scroll view after reload
@@ -3681,9 +3686,9 @@ - (void)processFieldEditorResult:(id)data contextInfo:(NSDictionary*)contextInfo
36813686
}
36823687
}
36833688

3684-
if(fieldEditor) {
3685-
SPClear(fieldEditor);
3686-
}
3689+
// this is a delegate method of the field editor controller. calling release
3690+
// now would risk a dealloc while it is still our parent on the stack:
3691+
[fieldEditor autorelease], fieldEditor = nil;
36873692

36883693
// Preserve focus and restore selection indexes if appropriate
36893694
[[tableDocumentInstance parentWindow] makeFirstResponder:customQueryView];

Diff for: Source/SPTableContent.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -3363,10 +3363,10 @@ - (void)processFieldEditorResult:(id)data contextInfo:(NSDictionary*)contextInfo
33633363
}
33643364
}
33653365
}
3366-
3367-
if(fieldEditor) {
3368-
SPClear(fieldEditor);
3369-
}
3366+
3367+
// this is a delegate method of the field editor controller. calling release
3368+
// now would risk a dealloc while it is still our parent on the stack:
3369+
[fieldEditor autorelease], fieldEditor = nil;
33703370

33713371
[[tableContentView window] makeFirstResponder:tableContentView];
33723372

Diff for: Source/SPTableContentDelegate.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
235235
#endif
236236
if (tableView == tableContentView) {
237237

238+
// Nothing is editable while the field editor is running.
239+
// This guards against a special case where accessibility services might
240+
// check if a table field is editable while the sheet is running.
241+
if (fieldEditor) return NO;
242+
238243
// Ensure that row is editable since it could contain "(not loaded)" columns together with
239244
// issue that the table has no primary key
240245
NSString *wherePart = [NSString stringWithString:[self argumentForRow:[tableContentView selectedRow]]];
@@ -303,8 +308,6 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
303308
fieldEncoding = [columnDefinition objectForKey:@"charset_name"];
304309
}
305310

306-
if (fieldEditor) SPClear(fieldEditor);
307-
308311
fieldEditor = [[SPFieldEditorController alloc] init];
309312

310313
[fieldEditor setEditedFieldInfo:[NSDictionary dictionaryWithObjectsAndKeys:
@@ -709,8 +712,8 @@ - (void)controlTextDidChange:(NSNotification *)notification
709712

710713
/**
711714
* If the user selected a table cell which is a blob field and tried to edit it
712-
* cancel the fieldEditor, display the field editor sheet instead for editing
713-
* and re-enable the fieldEditor after editing.
715+
* cancel the inline edit, display the field editor sheet instead for editing
716+
* and re-enable inline editing after closing the sheet.
714717
*/
715718
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)aFieldEditor
716719
{
@@ -767,6 +770,7 @@ - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)aFieldEdit
767770
// Cancel editing
768771
[control abortEditing];
769772

773+
NSAssert(fieldEditor == nil, @"Method should not to be called while a field editor sheet is open!");
770774
// Call the field editor sheet
771775
[self tableView:tableContentView shouldEditTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], column) row:row];
772776

0 commit comments

Comments
 (0)