1
+ #import < time.h>
1
2
#import < QuartzCore/QuartzCore.h>
2
3
#import " MMTabline.h"
3
4
@@ -554,6 +555,19 @@ - (void)scrollTabToVisibleAtIndex:(NSUInteger)index
554
555
{
555
556
if (_tabs.count == 0 ) return ;
556
557
558
+ // Get the amount of time elapsed between the previous invocation
559
+ // of this method and now. Use this elapsed time to set the animation
560
+ // duration such that rapid invocations of this method result in
561
+ // faster animations. For example, the user might hold down the tab
562
+ // scrolling buttons (causing them to repeatedly fire) or they might
563
+ // rapidly click them.
564
+ static NSTimeInterval lastTime = 0 ;
565
+ struct timespec t;
566
+ clock_gettime (CLOCK_MONOTONIC, &t);
567
+ NSTimeInterval currentTime = t.tv_sec + t.tv_nsec * 1 .e -9 ;
568
+ NSTimeInterval elapsedTime = currentTime - lastTime;
569
+ lastTime = currentTime;
570
+
557
571
NSRect tabFrame = _tabs[index].frame ;
558
572
NSRect clipBounds = _scrollView.contentView .bounds ;
559
573
// One side or the other of the selected tab is clipped.
@@ -565,7 +579,10 @@ - (void)scrollTabToVisibleAtIndex:(NSUInteger)index
565
579
// Left side of the selected tab is clipped.
566
580
clipBounds.origin .x = tabFrame.origin .x ;
567
581
}
582
+ [NSAnimationContext beginGrouping ];
583
+ [NSAnimationContext .currentContext setDuration: elapsedTime < 0.2 ? 0.05 : 0.2 ];
568
584
_scrollView.contentView .animator .bounds = clipBounds;
585
+ [NSAnimationContext endGrouping ];
569
586
}
570
587
}
571
588
0 commit comments