Skip to content

Commit

Permalink
fix: command line view will not visible on Xcode 13
Browse files Browse the repository at this point in the history
fix #381
  • Loading branch information
r-plus committed Oct 3, 2021
1 parent 6d5a46c commit 8a251fa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions XVim2/Xcode/SourceEditorViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@interface SourceEditorViewProxy ()
@property (weak) _TtC15IDESourceEditor19IDESourceEditorView* sourceEditorView;
@property NSLayoutConstraint* cmdLineBottomAnchor;
@property NSEdgeInsets originalScrollViewInsets;
@end

@implementation SourceEditorViewProxy {
Expand Down Expand Up @@ -632,6 +633,7 @@ - (XVimCommandLine*)commandLine
}
static CGFloat XvimCommandLineHeight = 20;
static CGFloat XvimCommandLineAnimationDuration = 0.1;
static CGFloat IDEKit_BottomBarViewHeight = 27;

- (BOOL)isShowingCommandLine { return self.commandLine.superview != nil; }

Expand All @@ -645,7 +647,7 @@ - (void)showCommandLine
NSView* layoutView = [scrollView superview];
[layoutView addSubview:self.commandLine];
_cmdLineBottomAnchor = [layoutView.bottomAnchor constraintEqualToAnchor:self.commandLine.bottomAnchor
constant:-XvimCommandLineHeight];
constant:0];
_cmdLineBottomAnchor.active = YES;
[layoutView.widthAnchor constraintEqualToAnchor:self.commandLine.widthAnchor multiplier:1.0].active = YES;
[layoutView.leftAnchor constraintEqualToAnchor:self.commandLine.leftAnchor].active = YES;
Expand All @@ -663,7 +665,8 @@ - (void)showCommandLine
[NSAnimationContext runAnimationGroup:^(NSAnimationContext* _Nonnull context) {
context.duration = XvimCommandLineAnimationDuration;
NSEdgeInsets insets = scrollView.contentInsets;
self->_cmdLineBottomAnchor.animator.constant = 0;
self->_originalScrollViewInsets = insets;
self->_cmdLineBottomAnchor.animator.constant = IDEKit_BottomBarViewHeight;
insets.bottom += XvimCommandLineHeight;
scrollView.animator.contentInsets = insets;
[scrollView setUpdatingAutoContentInsets:YES];
Expand Down Expand Up @@ -696,6 +699,7 @@ - (void)hideCommandLine
} completionHandler:^{
[self.commandLine removeFromSuperview];
self->_cmdLineBottomAnchor = nil;
self->_originalScrollViewInsets = NSEdgeInsetsZero;
}];
}
}
Expand All @@ -708,7 +712,8 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
if ([keyPath isEqualToString:@"contentInsets"]) {
let scrollView = self.sourceEditorView.scrollView;
NSEdgeInsets insets = scrollView.contentInsets;
if (self.isShowingCommandLine && insets.bottom == 0) {
// NOTE: insets.bottom value sometimes 1pt difference to original.
if (self.isShowingCommandLine && insets.bottom <= self->_originalScrollViewInsets.bottom + 1) {
insets.bottom += XvimCommandLineHeight;
scrollView.contentInsets = insets;
}
Expand Down

0 comments on commit 8a251fa

Please sign in to comment.