Skip to content

Commit 5036e40

Browse files
committed
Tab scroll buttons are more responsive
Holding down scroll buttons or rapidly clicking them results in faster scrolling.
1 parent 2d70c5b commit 5036e40

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/MacVim/MMTabline/MMTabline.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#import <time.h>
12
#import <QuartzCore/QuartzCore.h>
23
#import "MMTabline.h"
34

@@ -554,6 +555,19 @@ - (void)scrollTabToVisibleAtIndex:(NSUInteger)index
554555
{
555556
if (_tabs.count == 0) return;
556557

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+
557571
NSRect tabFrame = _tabs[index].frame;
558572
NSRect clipBounds = _scrollView.contentView.bounds;
559573
// One side or the other of the selected tab is clipped.
@@ -565,7 +579,10 @@ - (void)scrollTabToVisibleAtIndex:(NSUInteger)index
565579
// Left side of the selected tab is clipped.
566580
clipBounds.origin.x = tabFrame.origin.x;
567581
}
582+
[NSAnimationContext beginGrouping];
583+
[NSAnimationContext.currentContext setDuration:elapsedTime < 0.2 ? 0.05 : 0.2];
568584
_scrollView.contentView.animator.bounds = clipBounds;
585+
[NSAnimationContext endGrouping];
569586
}
570587
}
571588

0 commit comments

Comments
 (0)