Skip to content

Commit ea10635

Browse files
committed
MMTabline: Clear all tabs while showing / hiding tab line
When the GUI tab line is hidden (either due to `set showtabline` or `set go-=e`), Vim stops sending update messages to the GUI. This means the tabs were stale and would never get cleared, and the moment we show the tabs we see a confusing animation when the tabs quicly try to rearrange to match Vim's state. To fix this, just make sure to clean up and remove all of them when we hide the tab line.
1 parent 4470b5f commit ea10635

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

src/MacVim/MMTabline/MMTabline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- (NSInteger)addTabAtIndex:(NSInteger)index;
3434

3535
- (void)closeTab:(MMTab *)tab force:(BOOL)force layoutImmediately:(BOOL)layoutImmediately;
36+
- (void)closeAllTabs;
3637

3738
/// Batch update all the tabs using tab tags as unique IDs. Tab line will handle
3839
/// creating / removing tabs as necessary, and moving tabs to their new

src/MacVim/MMTabline/MMTabline.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ - (void)closeTab:(MMTab *)tab force:(BOOL)force layoutImmediately:(BOOL)layoutIm
315315
}
316316
}
317317

318+
- (void)closeAllTabs
319+
{
320+
_selectedTabIndex = -1;
321+
_draggedTab = nil;
322+
_initialDraggedTabIndex = _finalDraggedTabIndex = NSNotFound;
323+
for (MMTab *tab in _tabs) {
324+
[tab removeFromSuperview];
325+
}
326+
[_tabs removeAllObjects];
327+
[self fixupLayoutWithAnimation:NO];
328+
}
329+
318330
- (void)updateTabsByTags:(NSInteger *)tags len:(NSUInteger)len delayTabResize:(BOOL)delayTabResize
319331
{
320332
BOOL needUpdate = NO;
@@ -564,7 +576,13 @@ - (void)fixupTabZOrder
564576

565577
- (void)fixupLayoutWithAnimation:(BOOL)shouldAnimate delayResize:(BOOL)delayResize
566578
{
567-
if (_tabs.count == 0) return;
579+
if (_tabs.count == 0) {
580+
NSRect frame = _tabsContainer.frame;
581+
frame.size.width = 0;
582+
_tabsContainer.frame = frame;
583+
[self updateTabScrollButtonsEnabledState];
584+
return;
585+
}
568586

569587
if (delayResize) {
570588
// The pending delayed resize is trigged by mouse exit, but if we are

src/MacVim/MMVimView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
- (MMTabline *)tabline;
4646
- (IBAction)addNewTab:(id)sender;
47+
- (void)showTabline:(BOOL)on;
4748
- (void)updateTabsWithData:(NSData *)data;
4849
- (void)refreshTabProperties;
4950

src/MacVim/MMVimView.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,21 @@ - (void)setDesiredRows:(int)r columns:(int)c
251251

252252
- (IBAction)addNewTab:(id)sender
253253
{
254+
// Callback from the "Create a new tab button". We override this so we can
255+
// send a message to Vim first and let it handle it before replying back.
254256
[vimController sendMessage:AddNewTabMsgID data:nil];
255257
}
256258

259+
- (void)showTabline:(BOOL)on
260+
{
261+
[tabline setHidden:!on];
262+
if (!on) {
263+
// When the tab is not shown we don't get tab updates from Vim. We just
264+
// close all of them as otherwise we will be holding onto stale states.
265+
[tabline closeAllTabs];
266+
}
267+
}
268+
257269
/// Callback from Vim to update the tabline with new tab data
258270
- (void)updateTabsWithData:(NSData *)data
259271
{

src/MacVim/MMWindowController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ - (void)processInputQueueDidFinish
868868

869869
- (void)showTabline:(BOOL)on
870870
{
871-
[[vimView tabline] setHidden:!on];
871+
[vimView showTabline:on];
872872
[self updateTablineSeparator];
873873
shouldMaximizeWindow = YES;
874874
}

0 commit comments

Comments
 (0)