Skip to content

Commit

Permalink
fix: add workaround for xvim added content insets for command line ba…
Browse files Browse the repository at this point in the history
…r will reset to 0 by xcode when add tab or change full screen state.
  • Loading branch information
r-plus committed Mar 20, 2021
1 parent 34a74cc commit 51cdc86
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions XVim2/Xcode/SourceEditorViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,13 @@ - (void)showCommandLine
insets.bottom += XvimCommandLineHeight;
scrollView.animator.contentInsets = insets;
[scrollView setUpdatingAutoContentInsets:YES];
}
completionHandler:^{
self.commandLine.needsDisplay = YES;
}];
} completionHandler:^{
self.commandLine.needsDisplay = YES;
// XVim added contentInsets.bottom value for command line bar will discard by Xcode
// when add tab, change fullscreen state etc.
// This observe is for re-add it.
[scrollView addObserver:self forKeyPath:@"contentInsets" options:NSKeyValueObservingOptionNew context:nil];
}];
}
}

Expand All @@ -681,6 +684,7 @@ - (void)hideCommandLine

let scrollView = [self.sourceEditorView scrollView];
if ([self.sourceEditorView.class isEqual:NSClassFromString(IDESourceEditorViewClassName)]) {
[scrollView removeObserver:self forKeyPath:@"contentInsets"];
NSEdgeInsets insets = scrollView.contentInsets;
insets.bottom -= XvimCommandLineHeight;

Expand All @@ -689,11 +693,25 @@ - (void)hideCommandLine
self->_cmdLineBottomAnchor.animator.constant = -XvimCommandLineHeight;
scrollView.animator.contentInsets = insets;
[scrollView setUpdatingAutoContentInsets:YES];
} completionHandler:^{
[self.commandLine removeFromSuperview];
self->_cmdLineBottomAnchor = nil;
}];
}
}

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context
{
if ([keyPath isEqualToString:@"contentInsets"]) {
let scrollView = self.sourceEditorView.scrollView;
NSEdgeInsets insets = scrollView.contentInsets;
if (self.isShowingCommandLine && insets.bottom == 0) {
insets.bottom += XvimCommandLineHeight;
scrollView.contentInsets = insets;
}
completionHandler:^{
[self.commandLine removeFromSuperview];
self->_cmdLineBottomAnchor = nil;
}];
}
}

Expand Down

0 comments on commit 51cdc86

Please sign in to comment.