Skip to content

Commit bc51f5e

Browse files
authored
Merge pull request #1442 from ychin/scroll-one-direction-only
Add option to only scroll in one direction when using trackpad
2 parents 76cc4e2 + 881463f commit bc51f5e

File tree

8 files changed

+86
-18
lines changed

8 files changed

+86
-18
lines changed

runtime/doc/gui_mac.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ The ODB editor protocol is documented at:
260260
3. Settings *macvim-prefs* *macvim-preferences* *macvim-settings*
261261

262262
Some settings are global to the MacVim application and would not make sense as
263-
Vim options. These settings are stored in the user defaults database and can
264-
be accessed via the "MacVim.Settings…" ("MacVim.Preferences…" in macOS 12
265-
Monterey and older) menu item.
263+
Vim options (see |macvim-options|). These settings are stored in the user
264+
defaults database and can be accessed via the "MacVim.Settings…"
265+
("MacVim.Preferences…" in macOS 12 Monterey and older) menu item.
266266

267267
*macvim-user-defaults*
268268
Not all entries in the user defaults database are exposed via the settings
@@ -299,6 +299,7 @@ KEY VALUE ~
299299
*MMTitlebarAppearsTransparent* enable a transparent titlebar [bool]
300300
*MMAppearanceModeSelection* dark mode selection (|macvim-dark-mode|)[bool]
301301
*MMRendererClipToRow* clip tall characters to the row they are on [bool]
302+
*MMScrollOneDirectionOnly* scroll along one axis only when using trackpad [bool]
302303
*MMSmoothResize* allow smooth resizing of MacVim window [bool]
303304
*MMShareFindPboard* share search text to Find Pasteboard [bool]
304305
*MMShowAddTabButton* enable "add tab" button on tabline [bool]

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,6 +5586,7 @@ MMNoTitleBarWindow gui_mac.txt /*MMNoTitleBarWindow*
55865586
MMNonNativeFullScreenSafeAreaBehavior gui_mac.txt /*MMNonNativeFullScreenSafeAreaBehavior*
55875587
MMNonNativeFullScreenShowMenu gui_mac.txt /*MMNonNativeFullScreenShowMenu*
55885588
MMRendererClipToRow gui_mac.txt /*MMRendererClipToRow*
5589+
MMScrollOneDirectionOnly gui_mac.txt /*MMScrollOneDirectionOnly*
55895590
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
55905591
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*
55915592
MMShowWhatsNewOnStartup gui_mac.txt /*MMShowWhatsNewOnStartup*

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,11 @@
495495
<point key="canvasLocation" x="137.5" y="435"/>
496496
</customView>
497497
<customView id="Bnq-Nx-GJH" userLabel="Input">
498-
<rect key="frame" x="0.0" y="0.0" width="483" height="84"/>
498+
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
499499
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
500500
<subviews>
501501
<customView id="DAP-Yi-QU0" userLabel="Trackpad">
502-
<rect key="frame" x="20" y="46" width="433" height="18"/>
502+
<rect key="frame" x="20" y="72" width="433" height="18"/>
503503
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
504504
<subviews>
505505
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="f18-Wr-EgZ">
@@ -526,10 +526,10 @@
526526
</subviews>
527527
</customView>
528528
<customView id="GZa-RH-fza" userLabel="Mouse">
529-
<rect key="frame" x="20" y="20" width="433" height="18"/>
529+
<rect key="frame" x="20" y="46" width="433" height="18"/>
530530
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
531531
<subviews>
532-
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="3Tx-8j-zQR">
532+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="3Tx-8j-zQR">
533533
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
534534
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
535535
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Mouse:" id="imK-Tr-YuD">
@@ -551,8 +551,35 @@
551551
</button>
552552
</subviews>
553553
</customView>
554+
<customView id="aUx-jX-mJJ" userLabel="Scrolling">
555+
<rect key="frame" x="20" y="20" width="433" height="18"/>
556+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
557+
<subviews>
558+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="8cr-OB-jXX" userLabel="Scrolling:">
559+
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
560+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
561+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Scrolling" id="UFM-zM-qC7" userLabel="Scrolling:">
562+
<font key="font" metaFont="system"/>
563+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
564+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
565+
</textFieldCell>
566+
</textField>
567+
<button id="Cdy-wF-SD6">
568+
<rect key="frame" x="189" y="-1" width="187" height="18"/>
569+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
570+
<string key="toolTip">When set, will only scroll along either the vertical or horizontal axis when using trackpad. This prevents horizontal drift when scrolling vertically on a trackpad.</string>
571+
<buttonCell key="cell" type="check" title="Scroll in one direction only" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="psN-UG-I7i">
572+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
573+
<font key="font" metaFont="system"/>
574+
</buttonCell>
575+
<connections>
576+
<binding destination="58" name="value" keyPath="values.MMScrollOneDirectionOnly" id="EHQ-Yi-7ou"/>
577+
</connections>
578+
</button>
579+
</subviews>
580+
</customView>
554581
</subviews>
555-
<point key="canvasLocation" x="137.5" y="692"/>
582+
<point key="canvasLocation" x="137.5" y="705"/>
556583
</customView>
557584
<customView id="620" userLabel="Advanced">
558585
<rect key="frame" x="0.0" y="0.0" width="483" height="367"/>

src/MacVim/MMAppController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ + (void)initialize
268268
[NSNumber numberWithBool:NO], MMUpdaterPrereleaseChannelKey,
269269
@"", MMLastUsedBundleVersionKey,
270270
[NSNumber numberWithBool:YES], MMShowWhatsNewOnStartupKey,
271+
[NSNumber numberWithBool:0], MMScrollOneDirectionOnlyKey,
271272
nil];
272273

273274
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];

src/MacVim/MMTextViewHelper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323

2424
@interface MMTextViewHelper : NSObject {
25+
enum ScrollingDirection {
26+
ScrollingDirectionUnknown = 0,
27+
ScrollingDirectionVertical,
28+
ScrollingDirectionHorizontal,
29+
};
30+
2531
id textView;
2632
BOOL isDragging;
2733
int dragRow;
@@ -38,6 +44,7 @@
3844
NSDate *mouseDownTime;
3945
CGFloat scrollingDeltaX;
4046
CGFloat scrollingDeltaY;
47+
enum ScrollingDirection scrollingDirection; ///< The fixed scrolling direction when using track pad (if configured to use it)
4148

4249
// Input Manager
4350
NSRange imRange;

src/MacVim/MMTextViewHelper.m

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,44 @@ - (void)scrollWheel:(NSEvent *)event
305305

306306
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
307307
if ([event hasPreciseScrollingDeltas]) {
308-
NSSize cellSize = [textView cellSize];
309-
float thresholdX = cellSize.width;
310-
float thresholdY = cellSize.height;
311-
scrollingDeltaX += [event scrollingDeltaX];
308+
const NSEventPhase phase = event.phase;
309+
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
310+
311+
CGFloat eventScrollingDeltaX = event.scrollingDeltaX;
312+
CGFloat eventScrollingDeltaY = event.scrollingDeltaY;
313+
314+
// If user wants to only scroll in one direction to prevent accidental
315+
// side scroll, we lock that in at the beginning of a scroll gesture.
316+
// Note that we choose Y if both X and Y deltas exist, because most of
317+
// the time, the user is doing a vertical scroll.
318+
if (phase == NSEventPhaseMayBegin || phase == NSEventPhaseBegan) {
319+
scrollingDirection = ScrollingDirectionUnknown;
320+
}
321+
if (scrollingDirection == ScrollingDirectionUnknown) {
322+
if (event.scrollingDeltaY != 0) {
323+
scrollingDirection = ScrollingDirectionVertical;
324+
} else if (event.scrollingDeltaX != 0) {
325+
scrollingDirection = ScrollingDirectionHorizontal;
326+
}
327+
}
328+
if ([ud boolForKey:MMScrollOneDirectionOnlyKey]) {
329+
if (scrollingDirection == ScrollingDirectionVertical) {
330+
eventScrollingDeltaX = 0;
331+
} else if (scrollingDirection == ScrollingDirectionHorizontal) {
332+
eventScrollingDeltaY = 0;
333+
}
334+
}
335+
336+
const NSSize cellSize = [textView cellSize];
337+
const float thresholdX = cellSize.width;
338+
const float thresholdY = cellSize.height;
339+
340+
scrollingDeltaX += eventScrollingDeltaX;
312341
if (fabs(scrollingDeltaX) > thresholdX) {
313342
dx = roundf(scrollingDeltaX / thresholdX);
314343
scrollingDeltaX -= thresholdX * dx;
315344
}
316-
scrollingDeltaY += [event scrollingDeltaY];
345+
scrollingDeltaY += eventScrollingDeltaY;
317346
if (fabs(scrollingDeltaY) > thresholdY) {
318347
dy = roundf(scrollingDeltaY / thresholdY);
319348
scrollingDeltaY -= thresholdY * dy;

src/MacVim/Miscellaneous.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern NSString *MMAllowForceClickLookUpKey;
6666
extern NSString *MMUpdaterPrereleaseChannelKey;
6767
extern NSString *MMLastUsedBundleVersionKey; // The last used version of MacVim before this launch
6868
extern NSString *MMShowWhatsNewOnStartupKey;
69+
extern NSString *MMScrollOneDirectionOnlyKey;
6970

7071

7172
// Enum for MMUntitledWindowKey

src/MacVim/Miscellaneous.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@
5353
NSString *MMNativeFullScreenKey = @"MMNativeFullScreen";
5454
NSString *MMUseMouseTimeKey = @"MMUseMouseTime";
5555
NSString *MMFullScreenFadeTimeKey = @"MMFullScreenFadeTime";
56-
NSString *MMNonNativeFullScreenShowMenuKey = @"MMNonNativeFullScreenShowMenu";
57-
NSString *MMNonNativeFullScreenSafeAreaBehaviorKey = @"MMNonNativeFullScreenSafeAreaBehavior";
56+
NSString *MMNonNativeFullScreenShowMenuKey = @"MMNonNativeFullScreenShowMenu";
57+
NSString *MMNonNativeFullScreenSafeAreaBehaviorKey = @"MMNonNativeFullScreenSafeAreaBehavior";
5858
NSString *MMSmoothResizeKey = @"MMSmoothResize";
5959
NSString *MMCmdLineAlignBottomKey = @"MMCmdLineAlignBottom";
60-
NSString *MMRendererClipToRowKey = @"MMRendererClipToRow";
60+
NSString *MMRendererClipToRowKey = @"MMRendererClipToRow";
6161
NSString *MMAllowForceClickLookUpKey = @"MMAllowForceClickLookUp";
6262
NSString *MMUpdaterPrereleaseChannelKey = @"MMUpdaterPrereleaseChannel";
63-
NSString *MMLastUsedBundleVersionKey = @"MMLastUsedBundleVersion";
64-
NSString *MMShowWhatsNewOnStartupKey = @"MMShowWhatsNewOnStartup";
63+
NSString *MMLastUsedBundleVersionKey = @"MMLastUsedBundleVersion";
64+
NSString *MMShowWhatsNewOnStartupKey = @"MMShowWhatsNewOnStartup";
65+
NSString *MMScrollOneDirectionOnlyKey = @"MMScrollOneDirectionOnly";
6566

6667

6768
@implementation NSIndexSet (MMExtras)

0 commit comments

Comments
 (0)