Skip to content

Commit 8406d28

Browse files
committed
MMTabline: expose scroll button settings and fix misc scroll issues
Allows the user to set whether to show the tabs scroll buttons or not in the preference pane as this is likely going to be a relatively popular configuration. Also, add new `macaction`'s for scrolling to selected tab and scrolling backward/forward so the user doesn't have to use the mouse to scroll. Fix misc issues with scrolling to a tab. The existing implementation was animating both the bounds size and position which would cause issues if the user resizes the window while still scrolling. Make sure the animation only touches the position. Also, the scrolling logic were using the physical locations of the scroll bounds to determine scroll condition, which doesn't account for the fact that it could be in the middle of animation. This led to rapid clicking of the scroll buttons having some clicks being ignored. Instead, fix it to always use the animated destination.
1 parent dffce69 commit 8406d28

11 files changed

Lines changed: 111 additions & 28 deletions

File tree

runtime/doc/gui_mac.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,11 @@ _cycleWindows: Select next window (similar to <D-`>)
573573
_cycleWindowsBackwards: Select previous window (similar to <D-S-`>)
574574
_removeWindowFromStageManagerSet Remove window from a Stage Manager Set. Same
575575
as the "Remove Window from Set" menu item.
576-
joinAllStageManagerSets Window will float among all Stage Manager sets
577-
unjoinAllStageManagerSets Window will only show up in its own set
576+
joinAllStageManagerSets: Window will float among all Stage Manager sets
577+
unjoinAllStageManagerSets: Window will only show up in its own set
578+
scrollToCurrentTab: Scroll to the selected tab in the GUI tab bar
579+
scrollBackwardOneTab: Scroll backward by one tab in the tab bar
580+
scrollForwardOneTab: Scroll forward by one tab in the tab bar
578581

579582
==============================================================================
580583
7. Toolbar *macvim-toolbar*

src/MacVim/Actions.plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<string></string>
99
<key>addNewTab:</key>
1010
<string></string>
11+
<key>scrollToCurrentTab:</key>
12+
<string></string>
13+
<key>scrollBackwardOneTab:</key>
14+
<string></string>
15+
<key>scrollForwardOneTab:</key>
16+
<string></string>
1117
<key>arrangeInFront:</key>
1218
<string></string>
1319
<key>clearRecentDocuments:</key>

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@
280280
<point key="canvasLocation" x="137.5" y="-17"/>
281281
</customView>
282282
<customView id="hr4-G4-3ZG" userLabel="Appearance">
283-
<rect key="frame" x="0.0" y="0.0" width="483" height="379"/>
283+
<rect key="frame" x="0.0" y="0.0" width="483" height="405"/>
284284
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
285285
<subviews>
286286
<customView id="fw0-VK-Nbz" userLabel="Dark mode selection">
287-
<rect key="frame" x="19" y="201" width="433" height="156"/>
287+
<rect key="frame" x="19" y="227" width="433" height="156"/>
288288
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
289289
<subviews>
290290
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="T40-Os-PUf" userLabel="Dark mode selection">
@@ -345,7 +345,7 @@
345345
</subviews>
346346
</customView>
347347
<customView id="7af-iK-4r7" userLabel="Titlebar appearance">
348-
<rect key="frame" x="19" y="118" width="433" height="75"/>
348+
<rect key="frame" x="19" y="144" width="433" height="75"/>
349349
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
350350
<subviews>
351351
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="9Rk-gT-kVC" userLabel="Titlebar appearance">
@@ -407,6 +407,33 @@
407407
</button>
408408
</subviews>
409409
</customView>
410+
<customView id="C3B-cu-RC2" userLabel="Tabs">
411+
<rect key="frame" x="20" y="118" width="432" height="18"/>
412+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
413+
<subviews>
414+
<button id="rCZ-9B-5RL">
415+
<rect key="frame" x="189" y="-1" width="244" height="18"/>
416+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
417+
<buttonCell key="cell" type="check" title="Show scroll buttons" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="Yqp-j5-BpX">
418+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
419+
<font key="font" metaFont="system"/>
420+
</buttonCell>
421+
<connections>
422+
<action selector="tabsPropertiesChanged:" target="-1" id="5xm-T0-e3B"/>
423+
<binding destination="58" name="value" keyPath="values.MMShowTabScrollButtons" id="KHi-zu-Jz2"/>
424+
</connections>
425+
</button>
426+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="qMc-Md-UwA" userLabel="Tabs">
427+
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
428+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
429+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Tabs:" id="iUO-3c-iff" userLabel="Tabs:">
430+
<font key="font" metaFont="system"/>
431+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
432+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
433+
</textFieldCell>
434+
</textField>
435+
</subviews>
436+
</customView>
410437
<customView id="BpJ-rH-ona" userLabel="Full Screen">
411438
<rect key="frame" x="19" y="72" width="433" height="38"/>
412439
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -508,7 +535,7 @@
508535
</subviews>
509536
</customView>
510537
</subviews>
511-
<point key="canvasLocation" x="137.5" y="444.5"/>
538+
<point key="canvasLocation" x="137.5" y="457.5"/>
512539
</customView>
513540
<customView id="Bnq-Nx-GJH" userLabel="Input">
514541
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
@@ -595,7 +622,7 @@
595622
</subviews>
596623
</customView>
597624
</subviews>
598-
<point key="canvasLocation" x="137.5" y="705"/>
625+
<point key="canvasLocation" x="138" y="775"/>
599626
</customView>
600627
<customView id="620" userLabel="Advanced">
601628
<rect key="frame" x="0.0" y="0.0" width="483" height="367"/>

src/MacVim/MMAppController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
- (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args;
8585

8686
- (void)refreshAllAppearances;
87+
- (void)refreshAllTabProperties;
8788
- (void)refreshAllFonts;
8889
- (void)refreshAllResizeConstraints;
8990
- (void)refreshAllTextViews;

src/MacVim/MMAppController.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,19 +1229,22 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
12291229

12301230
- (void)refreshAllAppearances
12311231
{
1232-
const NSUInteger count = [vimControllers count];
1233-
for (unsigned i = 0; i < count; ++i) {
1234-
MMVimController *vc = [vimControllers objectAtIndex:i];
1232+
for (MMVimController *vc in vimControllers) {
12351233
[vc.windowController refreshApperanceMode];
12361234
}
12371235
}
12381236

1237+
- (void)refreshAllTabProperties
1238+
{
1239+
for (MMVimController *vc in vimControllers) {
1240+
[vc.windowController.vimView refreshTabProperties];
1241+
}
1242+
}
1243+
12391244
/// Refresh all Vim text views' fonts.
12401245
- (void)refreshAllFonts
12411246
{
1242-
const NSUInteger count = [vimControllers count];
1243-
for (unsigned i = 0; i < count; ++i) {
1244-
MMVimController *vc = [vimControllers objectAtIndex:i];
1247+
for (MMVimController *vc in vimControllers) {
12451248
[vc.windowController refreshFonts];
12461249
}
12471250
}
@@ -1250,9 +1253,7 @@ - (void)refreshAllFonts
12501253
/// and resize the windows to match the constraints.
12511254
- (void)refreshAllResizeConstraints
12521255
{
1253-
const NSUInteger count = [vimControllers count];
1254-
for (unsigned i = 0; i < count; ++i) {
1255-
MMVimController *vc = [vimControllers objectAtIndex:i];
1256+
for (MMVimController *vc in vimControllers) {
12561257
[vc.windowController updateResizeConstraints:YES];
12571258
}
12581259
}
@@ -1261,9 +1262,7 @@ - (void)refreshAllResizeConstraints
12611262
/// cmdline alignment properties to make sure they are pinned properly.
12621263
- (void)refreshAllTextViews
12631264
{
1264-
const NSUInteger count = [vimControllers count];
1265-
for (unsigned i = 0; i < count; ++i) {
1266-
MMVimController *vc = [vimControllers objectAtIndex:i];
1265+
for (MMVimController *vc in vimControllers) {
12671266
[vc.windowController.vimView.textView updateCmdlineRow];
12681267
vc.windowController.vimView.textView.needsDisplay = YES;
12691268
}

src/MacVim/MMPreferenceController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939

4040
// Appearance pane
4141
- (IBAction)fontPropertiesChanged:(id)sender;
42+
- (IBAction)tabsPropertiesChanged:(id)sender;
4243

4344
@end

src/MacVim/MMPreferenceController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ - (IBAction)fontPropertiesChanged:(id)sender
167167
[[MMAppController sharedInstance] refreshAllFonts];
168168
}
169169

170+
- (IBAction)tabsPropertiesChanged:(id)sender
171+
{
172+
[[MMAppController sharedInstance] refreshAllTabProperties];
173+
}
174+
170175
- (IBAction)smoothResizeChanged:(id)sender
171176
{
172177
[[MMAppController sharedInstance] refreshAllResizeConstraints];

src/MacVim/MMTabline/MMTabline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
- (void)selectTabAtIndex:(NSInteger)index;
5454
- (MMTab *)tabAtIndex:(NSInteger)index;
5555
- (void)scrollTabToVisibleAtIndex:(NSInteger)index;
56+
- (void)scrollLeftOneTab;
57+
- (void)scrollRightOneTab;
5658
- (void)setTablineSelBackground:(NSColor *)back foreground:(NSColor *)fore;
5759

5860
@end

src/MacVim/MMTabline/MMTabline.m

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
CGFloat remainder;
99
} TabWidth;
1010

11-
const CGFloat OptimumTabWidth = 200;
11+
const CGFloat OptimumTabWidth = 220;
1212
const CGFloat MinimumTabWidth = 100;
1313
const CGFloat TabOverlap = 6;
14+
const CGFloat ScrollOneTabAllowance = 0.25; // If we are showing 75+% of the tab, consider it to be fully shown when deciding whether to scroll to next tab.
1415

1516
static MMHoverButton* MakeHoverButton(MMTabline *tabline, NSString *imageName, NSString *tooltip, SEL action, BOOL continuous) {
1617
MMHoverButton *button = [MMHoverButton new];
@@ -759,7 +760,7 @@ - (void)updateTabScrollButtonsEnabledState
759760
- (void)scrollTabToVisibleAtIndex:(NSInteger)index
760761
{
761762
if (_tabs.count == 0) return;
762-
if (index < 0 || index >= _tabs.count) return;
763+
index = index < 0 ? 0 : (index >= _tabs.count ? _tabs.count - 1 : index);
763764

764765
// Get the amount of time elapsed between the previous invocation
765766
// of this method and now. Use this elapsed time to set the animation
@@ -780,8 +781,8 @@ - (void)scrollTabToVisibleAtIndex:(NSInteger)index
780781
NSTimeInterval elapsedTime = 0.1;
781782
#endif
782783

783-
NSRect tabFrame = _tabs[index].frame;
784-
NSRect clipBounds = _scrollView.contentView.bounds;
784+
NSRect tabFrame = _tabs[index].animator.frame;
785+
NSRect clipBounds =_scrollView.contentView.animator.bounds;
785786
// One side or the other of the selected tab is clipped.
786787
if (!NSContainsRect(clipBounds, tabFrame)) {
787788
if (NSMinX(tabFrame) > NSMinX(clipBounds)) {
@@ -793,18 +794,19 @@ - (void)scrollTabToVisibleAtIndex:(NSInteger)index
793794
}
794795
[NSAnimationContext beginGrouping];
795796
[NSAnimationContext.currentContext setDuration:elapsedTime < 0.2 ? 0.05 : 0.2];
796-
_scrollView.contentView.animator.bounds = clipBounds;
797+
[_scrollView.contentView.animator setBoundsOrigin:clipBounds.origin];
797798
[NSAnimationContext endGrouping];
798799
}
799800
}
800801

801802
- (void)scrollLeftOneTab
802803
{
803-
NSRect clipBounds = _scrollView.contentView.bounds;
804+
NSRect clipBounds = _scrollView.contentView.animator.bounds;
804805
for (NSInteger i = _tabs.count - 1; i >= 0; i--) {
805806
NSRect tabFrame = _tabs[i].frame;
806807
if (!NSContainsRect(clipBounds, tabFrame)) {
807-
if (NSMinX(tabFrame) < NSMinX(clipBounds)) {
808+
CGFloat allowance = i == 0 ? 0 : NSWidth(tabFrame) * ScrollOneTabAllowance;
809+
if (NSMinX(tabFrame) + allowance < NSMinX(clipBounds)) {
808810
[self scrollTabToVisibleAtIndex:i];
809811
break;
810812
}
@@ -814,11 +816,12 @@ - (void)scrollLeftOneTab
814816

815817
- (void)scrollRightOneTab
816818
{
817-
NSRect clipBounds = _scrollView.contentView.bounds;
819+
NSRect clipBounds = _scrollView.contentView.animator.bounds;
818820
for (NSInteger i = 0; i < _tabs.count; i++) {
819821
NSRect tabFrame = _tabs[i].frame;
820822
if (!NSContainsRect(clipBounds, tabFrame)) {
821-
if (NSMaxX(tabFrame) > NSMaxX(clipBounds)) {
823+
CGFloat allowance = i == _tabs.count - 1 ? 0 : NSWidth(tabFrame) * ScrollOneTabAllowance;
824+
if (NSMaxX(tabFrame) - allowance > NSMaxX(clipBounds)) {
822825
[self scrollTabToVisibleAtIndex:i];
823826
break;
824827
}

src/MacVim/MMVimView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444

4545
- (MMTabline *)tabline;
4646
- (IBAction)addNewTab:(id)sender;
47+
- (IBAction)scrollToCurrentTab:(id)sender;
48+
- (IBAction)scrollBackwardOneTab:(id)sender;
49+
- (IBAction)scrollForwardOneTab:(id)sender;
50+
- (void)showTabline:(BOOL)on;
4751
- (void)updateTabsWithData:(NSData *)data;
52+
- (void)refreshTabProperties;
4853

4954
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type;
5055
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident;

0 commit comments

Comments
 (0)