Skip to content

Fix scrollbar to update properly when switching Vim windows #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/MacVim/MMVimView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
NSMutableArray *scrollbars;
}

@property BOOL pendingPlaceScrollbars;
@property BOOL pendingLiveResize;

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

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

Expand Down
27 changes: 21 additions & 6 deletions src/MacVim/MMVimView.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ - (void)drawRect:(NSRect)rect
// looking tabs. However, the textured window background looks really
// weird behind the window resize throbber, so emulate the look of an
// NSScrollView in the bottom right corner.
if (![[self window] showsResizeIndicator] // XXX: make this a flag
if (![[self window] showsResizeIndicator]
|| !([[self window] styleMask] & NSWindowStyleMaskTexturedBackground))
return;

// This should not be reachable in 10.7 or above and is deprecated code.
// See documentation for showsResizeIndicator and placeScrollbars: comments.

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

// We might need to change the scrollbars that are visible.
[self placeScrollbars];
self.pendingPlaceScrollbars = YES;
}
}

Expand Down Expand Up @@ -424,6 +427,8 @@ - (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
[self addSubview:scroller];
[scrollbars addObject:scroller];
[scroller release];

self.pendingPlaceScrollbars = YES;
}

- (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident
Expand All @@ -434,6 +439,8 @@ - (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident

[scroller removeFromSuperview];
[scrollbars removeObjectAtIndex:idx];

self.pendingPlaceScrollbars = YES;

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

BOOL wasVisible = ![scroller isHidden];
[scroller setHidden:!visible];

self.pendingPlaceScrollbars = YES;

// If a scroller was hidden or shown then the vim view must resize. This
// is handled by the window controller (the vim view never resizes itself).
Expand Down Expand Up @@ -483,10 +492,16 @@ - (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
NSRange range = NSMakeRange(pos, len);
if (!NSEqualRanges(range, [scroller range])) {
[scroller setRange:range];
// TODO! Should only do this once per update.

// This could be sent because a text window was created or closed, so
// we might need to update which scrollbars are visible.
}
self.pendingPlaceScrollbars = YES;
}

- (void)finishPlaceScrollbars
{
if (self.pendingPlaceScrollbars) {
self.pendingPlaceScrollbars = NO;
[self placeScrollbars];
}
}
Expand Down Expand Up @@ -789,7 +804,7 @@ - (void)placeScrollbars

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

[self placeScrollbars];
self.pendingPlaceScrollbars = YES;

// It is possible that the current number of (rows,columns) is too big or
// too small to fit the new frame. If so, notify Vim that the text
Expand Down
5 changes: 5 additions & 0 deletions src/MacVim/MMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ - (void)processInputQueueDidFinish
keepOnScreen = NO;
shouldKeepGUISize = NO;
}

// Tell Vim view to update its scrollbars which is done once per update.
// Do it last so whatever resizing we have done above will take effect
// immediate too instead of waiting till next frame.
[vimView finishPlaceScrollbars];
}

- (void)showTabBar:(BOOL)on
Expand Down