Skip to content

Commit 8bac906

Browse files
authored
Merge pull request #1557 from ychin/mmtabs-vim-colorscheme-fixes
Tabs: Use TabLineFill fg, fix colorscheme w/ transparent/inverse highlights
2 parents 961c252 + aaf5503 commit 8bac906

File tree

8 files changed

+142
-85
lines changed

8 files changed

+142
-85
lines changed

runtime/colors/retrobox.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Maintainer: Maxim Kim <[email protected]>, ported from gruvbox8 of Lifepillar <[email protected]>
55
" Website: https://www.github.com/vim/colorschemes
66
" License: Vim License (see `:help license`)
7-
" Last Change: 2025 Jan 07
7+
" Last Change: 2025 Feb 15
88

99
" Generated by Colortemplate v2.2.3
1010

@@ -150,7 +150,7 @@ else
150150
hi StatusLine guifg=#bdae93 guibg=#3c3836 gui=bold,reverse cterm=bold,reverse
151151
hi StatusLineNC guifg=#ebdbb2 guibg=#3c3836 gui=reverse cterm=reverse
152152
hi TabLine guifg=#665c54 guibg=#ebdbb2 gui=NONE cterm=NONE
153-
hi TabLineFill guifg=#ebdbb2 guibg=#ebdbb2 gui=NONE cterm=NONE
153+
hi TabLineFill guifg=#3c3836 guibg=#ebdbb2 gui=NONE cterm=NONE
154154
hi TabLineSel guifg=#282828 guibg=#fbf1c7 gui=bold cterm=bold
155155
hi ToolbarButton guifg=#282828 guibg=#bdae93 gui=bold cterm=bold
156156
hi ToolbarLine guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
@@ -332,7 +332,7 @@ if s:t_Co >= 256
332332
hi StatusLine ctermfg=144 ctermbg=237 cterm=bold,reverse
333333
hi StatusLineNC ctermfg=187 ctermbg=237 cterm=reverse
334334
hi TabLine ctermfg=59 ctermbg=187 cterm=NONE
335-
hi TabLineFill ctermfg=187 ctermbg=187 cterm=NONE
335+
hi TabLineFill ctermfg=237 ctermbg=187 cterm=NONE
336336
hi TabLineSel ctermfg=235 ctermbg=230 cterm=bold
337337
hi ToolbarButton ctermfg=235 ctermbg=144 cterm=bold
338338
hi ToolbarLine ctermfg=NONE ctermbg=NONE cterm=NONE

src/MacVim/MMTabline/MMTabline.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
@property (nonatomic, readonly) NSInteger numberOfTabs;
2121
@property (nonatomic, retain, readonly) MMHoverButton *addTabButton;
2222

23-
@property (nonatomic, retain) NSColor *tablineBgColor;
24-
@property (nonatomic, retain) NSColor *tablineFgColor;
25-
@property (nonatomic, retain) NSColor *tablineSelBgColor;
26-
@property (nonatomic, retain) NSColor *tablineSelFgColor;
27-
@property (nonatomic, retain) NSColor *tablineFillFgColor;
28-
29-
// Derived colors that cannot be set directly
23+
// Main colors
24+
@property (nonatomic, readonly) NSColor *tablineBgColor;
25+
@property (nonatomic, readonly) NSColor *tablineFgColor;
26+
@property (nonatomic, readonly) NSColor *tablineSelBgColor;
27+
@property (nonatomic, readonly) NSColor *tablineSelFgColor;
28+
@property (nonatomic, readonly) NSColor *tablineFillBgColor;
29+
@property (nonatomic, readonly) NSColor *tablineFillFgColor;
30+
31+
// Derived colors from the main ones
3032
@property (nonatomic, readonly) NSColor *tablineUnfocusedFgColor;
3133
@property (nonatomic, readonly) NSColor *tablineUnfocusedSelFgColor;
3234
@property (nonatomic, readonly) NSColor *tablineStrokeColor;
@@ -69,7 +71,7 @@
6971
/// colors based on the system light/dark modes.
7072
- (void)setColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
7173
selBg:(NSColor *)selBg selFg:(NSColor *)selFg
72-
fill:(NSColor *)fill;
74+
fillBg:(NSColor *)fill fillFg:(NSColor *)fillFg;
7375

7476
/// Lets the tabline calculate best colors to use based on background and
7577
/// foreground colors of the selected tab. The colors cannot be nil.

src/MacVim/MMTabline/MMTabline.m

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ @implementation MMTabline
6767
@synthesize tablineFgColor = _tablineFgColor;
6868
@synthesize tablineSelBgColor = _tablineSelBgColor;
6969
@synthesize tablineSelFgColor = _tablineSelFgColor;
70-
@synthesize tablineFillFgColor = _tablineFillFgColor;
70+
@synthesize tablineFillBgColor = _tablineFillBgColor;
7171
@synthesize tablineUnfocusedFgColor = _tablineUnfocusedFgColor;
7272
@synthesize tablineUnfocusedSelFgColor = _tablineUnfocusedSelFgColor;
7373

@@ -150,7 +150,7 @@ - (BOOL)wantsUpdateLayer { return YES; }
150150

151151
- (void)updateLayer
152152
{
153-
self.layer.backgroundColor = self.tablineFillFgColor.CGColor;
153+
self.layer.backgroundColor = self.tablineFillBgColor.CGColor;
154154
}
155155

156156
- (void)viewDidChangeEffectiveAppearance
@@ -253,63 +253,33 @@ - (NSColor *)tablineBgColor
253253
}
254254
}
255255

256-
- (void)setTablineBgColor:(NSColor *)color
257-
{
258-
_tablineBgColor = color;
259-
[self updateTabStates];
260-
}
261-
262256
- (NSColor *)tablineFgColor
263257
{
264258
return _tablineFgColor ?: NSColor.secondaryLabelColor;
265259
}
266260

267-
- (void)setTablineFgColor:(NSColor *)color
268-
{
269-
_tablineFgColor = color;
270-
_tablineUnfocusedFgColor = nil;
271-
[self updateTabStates];
272-
}
273-
274261
- (NSColor *)tablineSelBgColor
275262
{
276263
return _tablineSelBgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
277264
? [NSColor colorWithWhite:0.95 alpha:1]
278265
: [NSColor colorWithWhite:0.4 alpha:1];
279266
}
280267

281-
- (void)setTablineSelBgColor:(NSColor *)color
282-
{
283-
_tablineSelBgColor = color;
284-
[self updateTabStates];
285-
}
286-
287268
- (NSColor *)tablineSelFgColor
288269
{
289270
return _tablineSelFgColor ?: NSColor.controlTextColor;
290271
}
291272

292-
- (void)setTablineSelFgColor:(NSColor *)color
293-
{
294-
_tablineSelFgColor = color;
295-
_tablineUnfocusedSelFgColor = nil;
296-
_addTabButton.fgColor = color;
297-
_backwardScrollButton.fgColor = color;
298-
_forwardScrollButton.fgColor = color;
299-
[self updateTabStates];
300-
}
301-
302-
- (NSColor *)tablineFillFgColor
273+
- (NSColor *)tablineFillBgColor
303274
{
304-
return _tablineFillFgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
275+
return _tablineFillBgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
305276
? [NSColor colorWithWhite:0.85 alpha:1]
306277
: [NSColor colorWithWhite:0.23 alpha:1];
307278
}
308279

309-
- (void)setTablineFillFgColor:(NSColor *)color
280+
- (NSColor *)tablineFillFgColor
310281
{
311-
_tablineFillFgColor = color;
312-
self.needsDisplay = YES;
282+
return _addTabButton.fgColor;
313283
}
314284

315285
- (NSColor *)tablineUnfocusedFgColor
@@ -570,22 +540,22 @@ - (MMTab *)tabAtIndex:(NSInteger)index
570540

571541
- (void)setColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
572542
selBg:(NSColor *)selBg selFg:(NSColor *)selFg
573-
fill:(NSColor *)fill
543+
fillBg:(NSColor *)fillBg fillFg:(NSColor *)fillFg
574544
{
575545
// Don't use the property mutators as we just want to update the states in
576546
// one go at the end.
577547
_tablineSelBgColor = selBg;
578548
_tablineSelFgColor = selFg;
579549
_tablineBgColor = tabBg;
580550
_tablineFgColor = tabFg;
581-
_tablineFillFgColor = fill;
551+
_tablineFillBgColor = fillBg;
582552

583553
_tablineUnfocusedFgColor = [_tablineFgColor blendedColorWithFraction:0.4 ofColor:_tablineBgColor];
584554
_tablineUnfocusedSelFgColor = [_tablineSelFgColor blendedColorWithFraction:0.38 ofColor:_tablineSelBgColor];
585555

586-
_addTabButton.fgColor = _tablineSelFgColor;
587-
_backwardScrollButton.fgColor = _tablineSelFgColor;
588-
_forwardScrollButton.fgColor = _tablineSelFgColor;
556+
_addTabButton.fgColor = fillFg;
557+
_backwardScrollButton.fgColor = fillFg;
558+
_forwardScrollButton.fgColor = fillFg;
589559

590560
[self updateTabStates];
591561
self.needsDisplay = YES;
@@ -615,7 +585,7 @@ - (void)setAutoColorsSelBg:(NSColor *)back fg:(NSColor *)fore;
615585
_tablineUnfocusedFgColor = [_tablineFgColor blendedColorWithFraction:0.4 ofColor:_tablineBgColor];
616586
_tablineUnfocusedSelFgColor = [_tablineSelFgColor blendedColorWithFraction:0.38 ofColor:_tablineSelBgColor];
617587

618-
_tablineFillFgColor = (brightness > 0.5)
588+
_tablineFillBgColor = (brightness > 0.5)
619589
? [back blendedColorWithFraction:0.25 ofColor:NSColor.blackColor]
620590
: [back blendedColorWithFraction:0.18 ofColor:NSColor.whiteColor];
621591

src/MacVim/MMVimView.m

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
MMTabColorTypeTabFg,
4141
MMTabColorTypeSelBg,
4242
MMTabColorTypeSelFg,
43-
MMTabColorTypeFill,
43+
MMTabColorTypeFillBg,
44+
MMTabColorTypeFillFg,
4445
MMTabColorTypeCount
4546
} MMTabColorType;
4647

@@ -377,7 +378,7 @@ - (void)refreshTabProperties
377378
{
378379
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
379380
tabline.showsTabScrollButtons = [ud boolForKey:MMShowTabScrollButtonsKey];
380-
[self updateTablineColors];
381+
[self updateTablineColors:MMTabColorsModeCount];
381382
}
382383

383384
- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
@@ -469,25 +470,35 @@ - (void)finishPlaceScrollbars
469470
}
470471
}
471472

472-
- (void)updateTablineColors
473+
- (void)updateTablineColors:(MMTabColorsMode)mode
473474
{
474475
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
475476
MMTabColorsMode tabColorsMode = [ud integerForKey:MMTabColorsModeKey];
477+
if (tabColorsMode >= MMTabColorsModeCount || tabColorsMode < 0) {
478+
// Catch-all for invalid values, which could be useful if we add new
479+
// modes and a user goes back and uses an old version of MacVim.
480+
tabColorsMode = MMTabColorsModeAutomatic;
481+
}
482+
if (mode != MMTabColorsModeCount && mode != tabColorsMode) {
483+
// Early out to avoid unnecessary updates if this is not relevant.
484+
return;
485+
}
476486
if (tabColorsMode == MMTabColorsModeDefaultColors) {
477487
[tabline setColorsTabBg:nil
478488
tabFg:nil
479489
selBg:nil
480490
selFg:nil
481-
fill:nil];
491+
fillBg:nil
492+
fillFg:nil];
482493
} else if (tabColorsMode == MMTabColorsModeVimColorscheme) {
483494
[tabline setColorsTabBg:tabColors[MMTabColorTypeTabBg]
484495
tabFg:tabColors[MMTabColorTypeTabFg]
485496
selBg:tabColors[MMTabColorTypeSelBg]
486497
selFg:tabColors[MMTabColorTypeSelFg]
487-
fill:tabColors[MMTabColorTypeFill]];
498+
fillBg:tabColors[MMTabColorTypeFillBg]
499+
fillFg:tabColors[MMTabColorTypeFillFg]];
488500
} else {
489-
// tabColorsMode == MMTabColorsModeAutomatic, but catch-all in case it's
490-
// set to an out-of-range number.
501+
// tabColorsMode == MMTabColorsModeAutomatic
491502
NSColor *back = [[self textView] defaultBackgroundColor];
492503
NSColor *fore = [[self textView] defaultForegroundColor];
493504
[tabline setAutoColorsSelBg:back fg:fore];
@@ -498,7 +509,7 @@ - (void)updateTablineColors
498509
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
499510
{
500511
[textView setDefaultColorsBackground:back foreground:fore];
501-
[self updateTablineColors];
512+
[self updateTablineColors:MMTabColorsModeAutomatic];
502513

503514
CALayer *backedLayer = [self layer];
504515
if (backedLayer) {
@@ -527,9 +538,9 @@ - (void)setTablineColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
527538
tabColors[MMTabColorTypeTabFg] = [tabFg retain];
528539
tabColors[MMTabColorTypeSelBg] = [selBg retain];
529540
tabColors[MMTabColorTypeSelFg] = [selFg retain];
530-
tabColors[MMTabColorTypeFill] = [fillBg retain];
531-
(void)fillFg; // We don't use fillFg as we don't draw anything in the empty area
532-
[self updateTablineColors];
541+
tabColors[MMTabColorTypeFillBg] = [fillBg retain];
542+
tabColors[MMTabColorTypeFillFg] = [fillFg retain];
543+
[self updateTablineColors:MMTabColorsModeVimColorscheme];
533544
}
534545

535546

src/MacVim/MMWindowController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ - (void)setTablineColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
743743
- (void)setWindowColorToTablineColor
744744
{
745745
NSColor *defaultBg = vimView.textView.defaultBackgroundColor;
746-
NSColor *tablineColor = vimView.tabline.tablineFillFgColor;
746+
NSColor *tablineColor = vimView.tabline.tablineFillBgColor;
747747
if (defaultBg.alphaComponent == 1.0) {
748748
[self setWindowBackgroundColor:tablineColor];
749749
} else {

src/MacVim/MacVimTests/MacVimTests.m

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ @interface MMVimController (Private)
3333
- (void)handleMessage:(int)msgid data:(NSData *)data;
3434
@end
3535

36+
@interface MMVimView (Tests)
37+
- (void)updateTablineColors:(MMTabColorsMode)mode;
38+
@end
39+
3640
// Test harness
3741
@implementation MMAppController (Tests)
3842
- (NSMutableArray*)vimControllers {
@@ -954,6 +958,63 @@ - (void) testResizeVimView {
954958
XCTAssertFalse(win.isRenderBlocked);
955959
}
956960

961+
#pragma mark Tabs tests
962+
963+
- (void)testTabColors {
964+
[self createTestVimWindow];
965+
966+
MMAppController *app = MMAppController.sharedInstance;
967+
MMVimView *vimView = [[[app keyVimController] windowController] vimView];
968+
MMTabline *tabline = [vimView tabline];
969+
970+
// Test Vim colorscheme mode
971+
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeVimColorscheme)];
972+
973+
[self sendStringToVim:@":hi Normal guifg=#ff0000 guibg=#00ff00\n" withMods:0];
974+
[self waitForVimProcess];
975+
[self sendStringToVim:@":hi TabLineSel guifg=#010203 guibg=#040506\n" withMods:0];
976+
[self sendStringToVim:@":hi clear TabLineFill\n" withMods:0];
977+
[self sendStringToVim:@":hi TabLine guifg=#111213 guibg=NONE gui=inverse\n" withMods:0];
978+
[self waitForEventHandlingAndVimProcess];
979+
980+
// Normal highlight groups
981+
XCTAssertEqualObjects(tabline.tablineSelBgColor, [NSColor colorWithRgbInt:0x040506]);
982+
XCTAssertEqualObjects(tabline.tablineSelFgColor, [NSColor colorWithRgbInt:0x010203]);
983+
// Cleared highlight group should be transparent and fall through to Normal group
984+
XCTAssertEqualObjects(tabline.tablineFillBgColor, [NSColor colorWithRgbInt:0x00ff00]);
985+
XCTAssertEqualObjects(tabline.tablineFillFgColor, [NSColor colorWithRgbInt:0xff0000]);
986+
// One color is transparent, and inversed fg/bg
987+
XCTAssertEqualObjects(tabline.tablineBgColor, [NSColor colorWithRgbInt:0x111213]);
988+
XCTAssertEqualObjects(tabline.tablineFgColor, [NSColor colorWithRgbInt:0x00ff00]);
989+
990+
// Cleared highlight group with inversed fg/bg
991+
[self sendStringToVim:@":hi TabLineFill gui=inverse\n" withMods:0];
992+
[self waitForEventHandlingAndVimProcess];
993+
XCTAssertEqualObjects(tabline.tablineFillBgColor, [NSColor colorWithRgbInt:0xff0000]);
994+
XCTAssertEqualObjects(tabline.tablineFillFgColor, [NSColor colorWithRgbInt:0x00ff00]);
995+
996+
// Test automatic colors mode
997+
// Selected tab should have the exact same background as Normal colors
998+
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeAutomatic)];
999+
[vimView updateTablineColors:MMTabColorsModeAutomatic];
1000+
XCTAssertEqualObjects(tabline.tablineSelBgColor, [NSColor colorWithRgbInt:0x00ff00]);
1001+
1002+
// Test default colors mode
1003+
// We just verify that the colors changed, rather than asserting the exact
1004+
// colors to make it easy to update tuning on them in the future.
1005+
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeDefaultColors)];
1006+
[vimView updateTablineColors:MMTabColorsModeDefaultColors];
1007+
1008+
vimView.window.appearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua];
1009+
[self waitForEventHandling];
1010+
XCTAssertEqual(tabline.tablineFillBgColor.colorSpace.colorSpaceModel, NSColorSpaceModelGray);
1011+
XCTAssertGreaterThan(tabline.tablineFillBgColor.whiteComponent, 0.5);
1012+
1013+
vimView.window.appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua];
1014+
[self waitForEventHandling];
1015+
XCTAssertLessThan(tabline.tablineFillBgColor.whiteComponent, 0.5);
1016+
}
1017+
9571018
#pragma mark Full screen tests
9581019

9591020
- (void)waitForNativeFullscreenEnter {

src/MacVim/Miscellaneous.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef enum : NSInteger {
110110
MMTabColorsModeDefaultColors = 0, ///< Use default colors based on macOS light/dark modes
111111
MMTabColorsModeAutomatic, ///< Automatically derive tab colors based on foreground/background colors
112112
MMTabColorsModeVimColorscheme, ///< Use Vim colorscheme TabLine/TabLineSel/TabLineFill colors
113+
MMTabColorsModeCount
113114
} MMTabColorsMode;
114115

115116
enum {

0 commit comments

Comments
 (0)