Skip to content

Commit 2d70c5b

Browse files
committed
Scroll wheel scrolls tabs horizontally
1 parent 210631e commit 2d70c5b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/MacVim/MMTabline/MMTabline.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ @implementation MMTabline
3838
NSInteger _finalDraggedTabIndex;
3939
MMHoverButton *_leftScrollButton;
4040
MMHoverButton *_rightScrollButton;
41+
id _scrollWheelEventMonitor;
4142
}
4243

4344
- (instancetype)initWithFrame:(NSRect)frameRect
@@ -78,6 +79,30 @@ - (instancetype)initWithFrame:(NSRect)frameRect
7879
[self addConstraint:_addTabButtonTrailingConstraint];
7980

8081
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didScroll:) name:NSViewBoundsDidChangeNotification object:_scrollView.contentView];
82+
83+
// Monitor for scroll wheel events so we can scroll the tabline
84+
// horizontally without the user having to hold down SHIFT.
85+
_scrollWheelEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel handler:^NSEvent * _Nullable(NSEvent * _Nonnull event) {
86+
NSPoint location = [_scrollView convertPoint:event.locationInWindow fromView:nil];
87+
// We want events:
88+
// where the mouse is over the _scrollView
89+
// and where the user is not modifying it with the SHIFT key
90+
// and initiated by the scroll wheel and not the trackpad
91+
if ([_scrollView mouse:location inRect:_scrollView.bounds]
92+
&& !event.modifierFlags
93+
&& !event.hasPreciseScrollingDeltas)
94+
{
95+
// Create a new scroll wheel event based on the original,
96+
// but set the new deltaX to the original's deltaY.
97+
// stackoverflow.com/a/38991946/111418
98+
CGEventRef cgEvent = CGEventCreateCopy(event.CGEvent);
99+
CGEventSetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis2, event.scrollingDeltaY);
100+
NSEvent *newEvent = [NSEvent eventWithCGEvent:cgEvent];
101+
CFRelease(cgEvent);
102+
return newEvent;
103+
}
104+
return event;
105+
}];
81106
}
82107
return self;
83108
}

0 commit comments

Comments
 (0)