Revision: 30060
          http://sourceforge.net/p/bibdesk/svn/30060
Author:   hofman
Date:     2026-02-25 18:03:40 +0000 (Wed, 25 Feb 2026)
Log Message:
-----------
register indexset of custom field rows rather than its first index, as it can 
be intermingled with added fields

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

Modified: trunk/bibdesk/BDSKEditor.h
===================================================================
--- trunk/bibdesk/BDSKEditor.h  2026-02-25 17:26:48 UTC (rev 30059)
+++ trunk/bibdesk/BDSKEditor.h  2026-02-25 18:03:40 UTC (rev 30060)
@@ -86,7 +86,7 @@
     
     NSMutableSet<NSString *> *addedFields;
     
-    NSInteger minNumberOfFields;
+    NSIndexSet *customFieldRows;
     
 // 
----------------------------------------------------------------------------------------
 // status bar stuff

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2026-02-25 17:26:48 UTC (rev 30059)
+++ trunk/bibdesk/BDSKEditor.m  2026-02-25 18:03:40 UTC (rev 30060)
@@ -2141,7 +2141,7 @@
 
 - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView 
doCommandBySelector:(SEL)commandSelector {
     NSInteger row = [tableView rowForView:control];
-    BOOL nonRemovable = row < minNumberOfFields;
+    BOOL removable = [customFieldRows containsIndex:row];
     if (commandSelector == @selector(cancelOperation:)) {
         [control abortEditing];
         if (row != -1)
@@ -2164,7 +2164,7 @@
     } else if (commandSelector != @selector(insertNewline:)) {
         return NO;
     }
-    if (nonRemovable || editorFlags.isEditing == NO || [[[control 
currentEditor] string] length] > 0) {
+    if (removable == NO || editorFlags.isEditing == NO || [[[control 
currentEditor] string] length] > 0) {
         [self editTextFieldAtRow:row forField:nil selection:nil];
     } else {
         // ending the edit may remove the row, which could lead to an invalid 
row selection
@@ -2409,7 +2409,7 @@
             [authorTableView reloadData];
         
         NSInteger row = [fields indexOfObject:changeKey];
-        if (row >= minNumberOfFields && ([NSString 
isEmptyAsComplexString:newValue] != [NSString 
isEmptyAsComplexString:oldValue])) {
+        if ([customFieldRows containsIndex:row] && ([NSString 
isEmptyAsComplexString:newValue] != [NSString 
isEmptyAsComplexString:oldValue])) {
                        // a custom field was added or removed
             [self reloadTableWithFields:[self currentFields] 
ignoreEditing:^(NSString *editedField){
                 return [editedField isEqualToString:changeKey];
@@ -2463,16 +2463,13 @@
 - (void)customFieldsDidChange:(NSNotification *)notification{
     BDSKFieldTypeMask change = [[[notification userInfo] 
objectForKey:BDSKChangedFieldTypesKey] unsignedIntegerValue];
     NSArray *currentFields = nil;
-    NSInteger oldMinNumberOfFields = minNumberOfFields;
     if ((change & (BDSKFieldTypeMaskInteger | BDSKFieldTypeMaskDefault)))
         currentFields = [self currentFields];
-    if (currentFields && [self commitEditingTableTextField]) {
+    if (currentFields && [self commitEditingTableTextField])
         [self reloadTableWithFields:currentFields ignoreEditing:nil];
-    } else {
-        minNumberOfFields = MIN(minNumberOfFields, oldMinNumberOfFields);
+    else
         if ((change & (BDSKFieldTypeMaskURL | BDSKFieldTypeMaskCitation)))
             [self updateTableViewDisplay];
-    }
     if ((change & BDSKFieldTypeMaskInteger))
         [self setupCollectionView];
     if ((change & BDSKFieldTypeMaskPerson))
@@ -3308,6 +3305,7 @@
     BDSKTypeManager *tm = [BDSKTypeManager sharedManager];
     NSString *type = [publication pubType];
     NSMutableSet *ignoredKeys = [[NSMutableSet alloc] 
initWithObjects:BDSKDateAddedString, BDSKDateModifiedString, BDSKColorString, 
nil];
+    NSMutableIndexSet *customIndexes = [NSMutableIndexSet indexSet];
     
     [ignoredKeys unionSet:[tm noteFieldsSet]];
     [ignoredKeys unionSet:[tm integerFieldsSet]];
@@ -3321,8 +3319,6 @@
         }
     }
     
-    minNumberOfFields = [currentFields count];
-    
     allFields = [[publication allFieldNames] mutableCopy];
     [allFields addNonDuplicateObjectsFromArray:[addedFields allObjects]];
     [allFields sortUsingSelector:@selector(caseInsensitiveNumericCompare:)];
@@ -3330,11 +3326,17 @@
     for (NSString *field in allFields) {
         if ([ignoredKeys containsObject:field] == NO) {
             [ignoredKeys addObject:field];
-            if ([addedFields containsObject:field] || NO == [[publication 
valueOfField:field inherit:NO] isEqualAsComplexString:@""])
+            if ([addedFields containsObject:field]) {
                 [currentFields addObject:field];
+            } else if (NO == [[publication valueOfField:field inherit:NO] 
isEqualAsComplexString:@""]) {
+                [customIndexes addIndex:[currentFields count]];
+                [currentFields addObject:field];
+            }
         }
     }
     
+    customFieldRows = [customIndexes copy];
+    
     if ([fields isEqualToArray:currentFields])
         currentFields = nil;
     

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