Revision: 15031
          http://sourceforge.net/p/skim-app/code/15031
Author:   hofman
Date:     2025-03-27 17:37:30 +0000 (Thu, 27 Mar 2025)
Log Message:
-----------
Shift selected and focused index when changing swatch colors

Modified Paths:
--------------
    trunk/SKColorSwatch.m

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2025-03-27 16:53:35 UTC (rev 15030)
+++ trunk/SKColorSwatch.m       2025-03-27 17:37:30 UTC (rev 15031)
@@ -614,7 +614,6 @@
 
 - (void)insertColor:(NSColor *)color atIndex:(NSInteger)i {
     if (color && i >= 0 && i <= (NSInteger)[colors count]) {
-        [self deactivate];
         [self willChangeColors];
         bezelWidth = [self contentWidth];
         [colors insertObject:color atIndex:i];
@@ -625,6 +624,10 @@
         else
             [self addSubview:itemView positioned:NSWindowAbove relativeTo:nil];
         [itemViews insertObject:itemView atIndex:i];
+        if (selectedIndex >= i)
+            selectedIndex++;
+        if (focusedIndex >= i)
+            focusedIndex++;
         [self didChangeColors];
         [self noteFocusRingMaskChanged];
         [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
@@ -644,7 +647,12 @@
 
 - (void)removeColorAtIndex:(NSInteger)i {
     if (i >= 0 && i < (NSInteger)[colors count] && [colors count] > 1) {
-        [self deactivate];
+        if (selectedIndex > i)
+            selectedIndex--;
+        else if (selectedIndex == i)
+            [self deactivate];
+        if (focusedIndex > i)
+            focusedIndex--;
         [self willChangeColors];
         bezelWidth = [self contentWidth];
         [colors removeObjectAtIndex:i];
@@ -672,7 +680,18 @@
 - (void)moveColorAtIndex:(NSInteger)from toIndex:(NSInteger)to {
     if (from >= 0 && to >= 0 && from != to) {
         NSColor *color = [colors objectAtIndex:from];
-        [self deactivate];
+        if (selectedIndex == from)
+            selectedIndex = to;
+        else if (selectedIndex > from && selectedIndex <= to)
+            selectedIndex--;
+        else if (selectedIndex < from && selectedIndex >= to)
+            selectedIndex++;
+        if (focusedIndex == from)
+            focusedIndex = to;
+        else if (focusedIndex > from && focusedIndex <= to)
+            focusedIndex--;
+        else if (focusedIndex < from && focusedIndex >= to)
+            focusedIndex++;
         [self willChangeColors];
         [colors removeObjectAtIndex:from];
         [colors insertObject:color atIndex:to];

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to