Revision: 30055
          http://sourceforge.net/p/bibdesk/svn/30055
Author:   hofman
Date:     2026-02-24 22:46:17 +0000 (Tue, 24 Feb 2026)
Log Message:
-----------
abort editing instead of setting editing string to current value to ignore 
editing

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2026-02-24 18:56:57 UTC (rev 30054)
+++ trunk/bibdesk/BDSKEditor.m  2026-02-24 22:46:17 UTC (rev 30055)
@@ -138,7 +138,7 @@
 - (void)collectionViewFrameDidChange:(NSNotification *)notification;
 - (void)setupTypePopUp;
 - (NSArray *)currentFields;
-- (void)reloadTableWithFields:(NSArray *)newFields;
+- (void)reloadTableWithFields:(NSArray *)newFields 
ignoreEditing:(BOOL)ignoreEditing;
 - (void)updateTableViewDisplay;
 - (void)registerForNotifications;
 - (void)updateCiteKeyDuplicateWarning;
@@ -230,7 +230,7 @@
     citeKeyConstraint = [[citeKeyTitle widthAnchor] 
constraintEqualToConstant:[citeKeyTitle intrinsicContentSize].width];
     [citeKeyConstraint setActive:YES];
     
-    [self reloadTableWithFields:[self currentFields]];
+    [self reloadTableWithFields:[self currentFields] ignoreEditing:NO];
     [self setupCollectionView];
     if (editorFlags.isEditable)
         [tableView registerForDraggedTypes:@[BDSKPasteboardTypePublications, 
NSPasteboardTypeString, (__bridge NSString *)kUTTypeURL, (__bridge NSString 
*)kUTTypeFileURL, NSURLPboardType, NSFilenamesPboardType]];
@@ -871,7 +871,7 @@
                     addedFields = [[NSMutableSet alloc] init];
                 [addedFields addObject:newField];
                 [tabView selectFirstTabViewItem:nil];
-                [self reloadTableWithFields:[self currentFields]];
+                [self reloadTableWithFields:[self currentFields] 
ignoreEditing:NO];
                 [self setKeyField:newField];
             }
         }];
@@ -920,7 +920,7 @@
                 [addedFields removeObject:oldField];
                 [tabView selectFirstTabViewItem:nil];
                 if ([NSString isEmptyAsComplexString:oldValue]) {
-                    [self reloadTableWithFields:[self currentFields]];
+                    [self reloadTableWithFields:[self currentFields] 
ignoreEditing:NO];
                 } else {
                     [publication setField:oldField toValue:nil];
                     [[self undoManager] 
setActionName:NSLocalizedString(@"Remove Field", @"Undo action name")];
@@ -2335,7 +2335,7 @@
        else if([changeKey isEqualToString:BDSKPubTypeString]){
         NSArray *currentFields = [self currentFields];
         if (currentFields)
-            [self reloadTableWithFields:currentFields];
+            [self reloadTableWithFields:currentFields ignoreEditing:NO];
                [self updateTypePopup];
         [self synchronizeWindowTitleWithDocumentName];
     }
@@ -2342,13 +2342,11 @@
     else if([changeKey isEqualToString:BDSKCrossrefString]){
         // Reset if the crossref changed.
         // We should first set the new value, because resetFields will set the 
edited value. This happens when it is set through drag/drop
+        BOOL ignoreEditing = NO;
         NSInteger editedRow = [tableView editedTextRow];
         if (editedRow != -1) {
             NSString *editedField = [fields objectAtIndex:editedRow];
-            if ([editedField isEqualToString:BDSKCrossrefString])
-                [[[self textFieldAtRow:editedRow] currentEditor] 
setString:newValue ?: @""];
-            else if ([NSString isEmptyAsComplexString:[publication 
valueOfField:editedField inherit:NO]])
-                [self resetEditingStringAtRow:editedRow field:editedField];
+            ignoreEditing = ([editedField isEqualToString:BDSKCrossrefString] 
|| [NSString isEmptyAsComplexString:[publication valueOfField:editedField 
inherit:NO]]);
         }
         NSArray *currentFields = nil;
         if ([NSString isEmptyString:newValue] != [NSString 
isEmptyString:oldValue])
@@ -2355,7 +2353,7 @@
             // Crossref field was added or removed
             currentFields = [self currentFields];
         // every field value could change
-        [self reloadTableWithFields:currentFields];
+        [self reloadTableWithFields:currentFields ignoreEditing:ignoreEditing];
         [authorTableView reloadData];
         [self synchronizeWindowTitleWithDocumentName];
     }
@@ -2362,12 +2360,8 @@
     else if(parentChanged){
         // Reset if our parent's cite key changed. Every field value could 
change.
         NSInteger editedRow = [tableView editedTextRow];
-        if (editedRow != -1) {
-            NSString *editedField = [fields objectAtIndex:editedRow];
-            if ([NSString isEmptyAsComplexString:[publication 
valueOfField:editedField inherit:NO]])
-                [self resetEditingStringAtRow:editedRow field:editedField];
-        }
-        [self reloadTableWithFields:nil];
+        BOOL ignoreEditing = (editedRow != -1 && [NSString 
isEmptyAsComplexString:[publication valueOfField:[fields 
objectAtIndex:editedRow] inherit:NO]]);
+        [self reloadTableWithFields:nil ignoreEditing:ignoreEditing];
         [authorTableView reloadData];
         [self synchronizeWindowTitleWithDocumentName];
         [self updateCiteKeyDuplicateWarning];
@@ -2399,10 +2393,7 @@
        }
     else if (changeKey == nil){
         // all fields are set
-        NSInteger editedRow = [tableView editedTextRow];
-        if (editedRow != -1)
-            [self resetEditingStringAtRow:editedRow field:[fields 
objectAtIndex:editedRow]];
-        [self reloadTableWithFields:[self currentFields]];
+        [self reloadTableWithFields:[self currentFields] ignoreEditing:YES];
         if (inheritedValueChanged == NO)
             [self setupCollectionView];
         [self synchronizeWindowTitleWithDocumentName];
@@ -2438,9 +2429,8 @@
         if (row >= minNumberOfFields && ([NSString 
isEmptyAsComplexString:newValue] != [NSString 
isEmptyAsComplexString:oldValue])) {
                        // a custom field was added or removed
             NSInteger editedRow = [tableView editedTextRow];
-            if (editedRow != -1 && [[fields objectAtIndex:editedRow] 
isEqualToString:changeKey])
-                [self resetEditingStringAtRow:editedRow field:changeKey];
-            [self reloadTableWithFields:[self currentFields]];
+            BOOL ignoreEditing = (editedRow != -1 && [[fields 
objectAtIndex:editedRow] isEqualToString:changeKey]);
+            [self reloadTableWithFields:[self currentFields] 
ignoreEditing:ignoreEditing];
         } else if (row != NSNotFound) {
             // a field value changed
             // don't use newValue, because this can be the parent's value
@@ -2463,7 +2453,9 @@
         for (id pub in pubs) {
             if ([crossref isCaseInsensitiveEqual:[pub citeKey]]) {
                 // changes in the parent cannot change the field names, as 
custom fields are never inherited
-                [self reloadTableWithFields:nil];
+                NSInteger editedRow = [tableView editedTextRow];
+                BOOL ignoreEditing = (editedRow != -1 && [NSString 
isEmptyAsComplexString:[publication valueOfField:[fields 
objectAtIndex:editedRow] inherit:NO]]);
+                [self reloadTableWithFields:nil ignoreEditing:ignoreEditing];
                 break;
             }
         }
@@ -2479,7 +2471,7 @@
     if ([self commitEditingTableTextField]) {
         NSArray *currentFields = [self currentFields];
         if (currentFields)
-            [self reloadTableWithFields:currentFields];
+            [self reloadTableWithFields:currentFields ignoreEditing:NO];
     }
 }
  
@@ -2492,7 +2484,7 @@
     if ((change & (BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskDefault)))
         currentFields = [self currentFields];
     if (currentFields && [self commitEditingTableTextField]) {
-        [self reloadTableWithFields:currentFields];
+        [self reloadTableWithFields:currentFields ignoreEditing:NO];
     } else {
         minNumberOfFields = MIN(minNumberOfFields, oldMinNumberOfFields);
         if ((change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskCitation)))
@@ -3247,18 +3239,21 @@
 
 #pragma mark Private
 
-- (void)reloadTableWithFields:(NSArray *)newFields{
-       // if we were editing in the tableView, we will restore the selected 
cell and the selection
+- (void)reloadTableWithFields:(NSArray *)newFields 
ignoreEditing:(BOOL)ignoreEditing{
+    // if we were editing in the tableView, we will restore the selected cell 
and the selection
     NSString *editedTitle = nil;
     NSArray *selection = nil;
     NSInteger editedRow = [tableView editedTextRow];
     if (editedRow != -1) {
+        NSTextField *textField = [self textFieldAtRow:editedRow];
         editedTitle = [fields objectAtIndex:editedRow];
-        selection = [(NSTextView *)[[self textFieldAtRow:editedRow] 
currentEditor] selectedRanges];
-        if ([[self window] makeFirstResponder:[self window]] == NO)
+        selection = [(NSTextView *)[textField currentEditor] selectedRanges];
+        if (ignoreEditing)
+            [textField abortEditing];
+        else if ([[self window] makeFirstResponder:[self window]] == NO)
              NSLog(@"Failed to commit edits in %s, trouble ahead", __func__);
     }
-       
+    
     // newFields should always be different from fields or nil
     if (newFields) {
         
@@ -3292,8 +3287,8 @@
         
     }
     
-       // restore the edited cell and its selection
-       if (editedTitle)
+    // restore the edited cell and its selection
+    if (editedTitle)
         [self editTextFieldAtRow:newFields ? NSNotFound : editedRow 
forField:editedTitle selection:selection];
 }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to