Skip to content

Commit

Permalink
Tab scroll buttons are more responsive
Browse files Browse the repository at this point in the history
Holding down scroll buttons or rapidly clicking
them results in faster scrolling.
  • Loading branch information
sfsam committed Jan 18, 2021
1 parent 2d70c5b commit 5036e40
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/MacVim/MMTabline/MMTabline.m
@@ -1,3 +1,4 @@
#import <time.h>
#import <QuartzCore/QuartzCore.h>
#import "MMTabline.h"

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

// Get the amount of time elapsed between the previous invocation
// of this method and now. Use this elapsed time to set the animation
// duration such that rapid invocations of this method result in
// faster animations. For example, the user might hold down the tab
// scrolling buttons (causing them to repeatedly fire) or they might
// rapidly click them.
static NSTimeInterval lastTime = 0;
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
NSTimeInterval currentTime = t.tv_sec + t.tv_nsec * 1.e-9;
NSTimeInterval elapsedTime = currentTime - lastTime;
lastTime = currentTime;

NSRect tabFrame = _tabs[index].frame;
NSRect clipBounds = _scrollView.contentView.bounds;
// One side or the other of the selected tab is clipped.
Expand All @@ -565,7 +579,10 @@ - (void)scrollTabToVisibleAtIndex:(NSUInteger)index
// Left side of the selected tab is clipped.
clipBounds.origin.x = tabFrame.origin.x;
}
[NSAnimationContext beginGrouping];
[NSAnimationContext.currentContext setDuration:elapsedTime < 0.2 ? 0.05 : 0.2];
_scrollView.contentView.animator.bounds = clipBounds;
[NSAnimationContext endGrouping];
}
}

Expand Down

0 comments on commit 5036e40

Please sign in to comment.