Skip to content

Commit bbc6060

Browse files
committed
Fix scrollbar to update properly when switching Vim windows
Previously, showing/hiding scrollbars didn't call placeScrollbars which was why sometimes when certain Vim commands that would show/hide Vim scrollbars get called, the scrollbar positions/sizes were not updated properly, leaving them with the wrong size. Fix this by adding a new pending flag so placeScrollbars only gets called once per update, and make sure showing/hiding scrollbars call it. Fix #802
1 parent d8bc23f commit bbc6060

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/MacVim/MMVimView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
NSMutableArray *scrollbars;
2828
}
2929

30+
@property BOOL pendingPlaceScrollbars;
3031
@property BOOL pendingLiveResize;
3132

3233
- (MMVimView *)initWithFrame:(NSRect)frame vimController:(MMVimController *)c;
@@ -51,6 +52,7 @@
5152
- (void)setScrollbarThumbValue:(float)val proportion:(float)prop
5253
identifier:(int32_t)ident;
5354
- (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident;
55+
- (void)finishPlaceScrollbars;
5456

5557
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore;
5658

src/MacVim/MMVimView.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ - (void)drawRect:(NSRect)rect
198198
// looking tabs. However, the textured window background looks really
199199
// weird behind the window resize throbber, so emulate the look of an
200200
// NSScrollView in the bottom right corner.
201-
if (![[self window] showsResizeIndicator] // XXX: make this a flag
201+
if (![[self window] showsResizeIndicator]
202202
|| !([[self window] styleMask] & NSWindowStyleMaskTexturedBackground))
203203
return;
204+
205+
// This should not be reachable in 10.7 or above and is deprecated code.
206+
// See documentation for showsResizeIndicator and placeScrollbars: comments.
204207

205208
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
206209
int sw = [NSScroller scrollerWidthForControlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleLegacy];
@@ -389,7 +392,7 @@ - (void)selectTabWithIndex:(int)idx
389392
vimTaskSelectedTab = NO;
390393

391394
// We might need to change the scrollbars that are visible.
392-
[self placeScrollbars];
395+
self.pendingPlaceScrollbars = YES;
393396
}
394397
}
395398

@@ -424,6 +427,8 @@ - (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
424427
[self addSubview:scroller];
425428
[scrollbars addObject:scroller];
426429
[scroller release];
430+
431+
self.pendingPlaceScrollbars = YES;
427432
}
428433

429434
- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident
@@ -434,6 +439,8 @@ - (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident
434439

435440
[scroller removeFromSuperview];
436441
[scrollbars removeObjectAtIndex:idx];
442+
443+
self.pendingPlaceScrollbars = YES;
437444

438445
// If a visible scroller was removed then the vim view must resize. This
439446
// is handled by the window controller (the vim view never resizes itself).
@@ -447,6 +454,8 @@ - (BOOL)showScrollbarWithIdentifier:(int32_t)ident state:(BOOL)visible
447454

448455
BOOL wasVisible = ![scroller isHidden];
449456
[scroller setHidden:!visible];
457+
458+
self.pendingPlaceScrollbars = YES;
450459

451460
// If a scroller was hidden or shown then the vim view must resize. This
452461
// is handled by the window controller (the vim view never resizes itself).
@@ -483,10 +492,16 @@ - (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
483492
NSRange range = NSMakeRange(pos, len);
484493
if (!NSEqualRanges(range, [scroller range])) {
485494
[scroller setRange:range];
486-
// TODO! Should only do this once per update.
487-
488495
// This could be sent because a text window was created or closed, so
489496
// we might need to update which scrollbars are visible.
497+
}
498+
self.pendingPlaceScrollbars = YES;
499+
}
500+
501+
- (void)finishPlaceScrollbars
502+
{
503+
if (self.pendingPlaceScrollbars) {
504+
self.pendingPlaceScrollbars = NO;
490505
[self placeScrollbars];
491506
}
492507
}
@@ -789,7 +804,7 @@ - (void)placeScrollbars
789804

790805
// Vertical scrollers must not cover the resize box in the
791806
// bottom-right corner of the window.
792-
if ([[self window] showsResizeIndicator] // XXX: make this a flag
807+
if ([[self window] showsResizeIndicator] // Note: This is deprecated as of 10.7, see below comment.
793808
&& rect.origin.y < scrollerWidth) {
794809
rect.size.height -= scrollerWidth - rect.origin.y;
795810
rect.origin.y = scrollerWidth;
@@ -914,7 +929,7 @@ - (void)frameSizeMayHaveChanged:(BOOL)keepGUISize
914929
NSRect textViewRect = [self textViewRectForVimViewSize:[self frame].size];
915930
[textView setFrame:textViewRect];
916931

917-
[self placeScrollbars];
932+
self.pendingPlaceScrollbars = YES;
918933

919934
// It is possible that the current number of (rows,columns) is too big or
920935
// too small to fit the new frame. If so, notify Vim that the text

src/MacVim/MMWindowController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ - (void)processInputQueueDidFinish
661661
keepOnScreen = NO;
662662
shouldKeepGUISize = NO;
663663
}
664+
665+
// Tell Vim view to update its scrollbars which is done once per update.
666+
// Do it last so whatever resizing we have done above will take effect
667+
// immediate too instead of waiting till next frame.
668+
[vimView finishPlaceScrollbars];
664669
}
665670

666671
- (void)showTabBar:(BOOL)on

0 commit comments

Comments
 (0)