Skip to content

Commit

Permalink
Scroll lower window relative to upper window split
Browse files Browse the repository at this point in the history
  • Loading branch information
dcsch committed Jul 25, 2019
1 parent 8d06849 commit 4675e14
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Yazmin/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,15 @@ CA
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JOw-pX-LSo">
<rect key="frame" x="0.0" y="0.0" width="720" height="408"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="3be-FR-WqR">
<rect key="frame" x="0.0" y="0.0" width="720" height="408"/>
<rect key="frame" x="0.0" y="0.0" width="705" height="408"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" verticallyResizable="YES" allowsDocumentBackgroundColorChange="YES" allowsNonContiguousLayout="YES" spellingCorrection="YES" smartInsertDelete="YES" id="YD4-1E-BWH" customClass="StoryTextView">
<rect key="frame" x="0.0" y="0.0" width="720" height="408"/>
<rect key="frame" x="0.0" y="0.0" width="705" height="408"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="720" height="408"/>
<size key="minSize" width="705" height="408"/>
<size key="maxSize" width="720" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
Expand All @@ -790,7 +790,7 @@ CA
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="W4T-ar-0bp">
<rect key="frame" x="704" y="0.0" width="16" height="408"/>
<rect key="frame" x="705" y="0.0" width="15" height="408"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down
4 changes: 2 additions & 2 deletions Yazmin/GridStoryFacet.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ - (void)eraseFromLine:(int)line {

// How many lines are already in the window?
NSArray<NSValue *> *ranges = [self rangesOfLines];
if (ranges.count > line) {
if (ranges.count >= line) {
NSRange range = ranges[line - 1].rangeValue;
NSRange rangeToEnd =
NSMakeRange(range.location, self.textStorage.length - range.location);
Expand All @@ -242,7 +242,7 @@ - (void)eraseFromLine:(int)line {

- (NSAttributedString *)attributedStringFromLine:(int)line {
NSArray<NSValue *> *ranges = [self rangesOfLines];
if (ranges.count > line) {
if (ranges.count >= line) {
NSRange range = ranges[line - 1].rangeValue;
NSRange rangeToEnd =
NSMakeRange(range.location, self.textStorage.length - range.location);
Expand Down
1 change: 1 addition & 0 deletions Yazmin/Story.m
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ - (void)splitWindow:(int)lines {
[_storyViewController printBox:str];
}

[storyFacet eraseFromLine:lines + 1];
storyFacet.numberOfLines = lines;
if (lines == 0)
_storyFacet = _facets[0];
Expand Down
8 changes: 6 additions & 2 deletions Yazmin/StoryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ - (void)resizeUpperWindow:(int)lines {
CGFloat upperHeight =
lines > 0 ? lineHeight * lines + 2.0 * upperView.textContainerInset.height
: 0;
CGFloat oldUpperHeight = upperHeightConstraint.constant;
upperHeightConstraint.constant = upperHeight;
upperView.textContainer.maximumNumberOfLines = lines;
_upperViewLineCount = lines;

// Scroll the lower window to compensate for the shift in position
// (we're keeping this simple for now: just scroll to the bottom)
[lowerView scrollPoint:NSMakePoint(0, lowerView.frame.size.height)];
NSRect rect = lowerScrollView.contentView.visibleRect;
CGFloat heightDiff = upperHeight - oldUpperHeight;
CGFloat y = MAX(0, rect.origin.y + heightDiff);
[self.view layoutSubtreeIfNeeded];
[lowerScrollView.contentView scrollToPoint:NSMakePoint(0, y)];
}

- (void)handleWindowWillClose:(NSNotification *)note {
Expand Down

0 comments on commit 4675e14

Please sign in to comment.