Skip to content

Commit

Permalink
Merge pull request #25 from CodingFriends/fix/23-line-number-view-ove…
Browse files Browse the repository at this point in the history
…ralys-text

Fixes bug #23 where line number view would overlay the text view
  • Loading branch information
greimers committed Jan 26, 2020
2 parents f9c8e28 + 31cfe88 commit 9d9b427
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Tincta.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@
CLANG_WARN_EMPTY_BODY = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4000;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 3UAW763979;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -849,6 +850,7 @@
);
LLVM_LTO = YES_THIN;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mrFridge.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = Tincta;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -866,6 +868,7 @@
CLANG_WARN_EMPTY_BODY = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 4000;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 3UAW763979;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -889,6 +892,7 @@
);
LLVM_LTO = YES_THIN;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MARKETING_VERSION = 4.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mrFridge.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = Tincta;
PROVISIONING_PROFILE = "";
Expand Down
4 changes: 3 additions & 1 deletion Tincta/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@
</textView>
</subviews>
</clipView>
<edgeInsets key="contentInsets" left="0.0" right="0.0" top="0.0" bottom="0.0"/>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="987">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -559,7 +560,7 @@
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="B6911588-0E91-49EC-97D2-69246860CA64" label="Syntax Coloring" paletteLabel="Syntax Coloring" id="966">
<nil key="toolTip"/>
<size key="minSize" width="110" height="25"/>
<size key="minSize" width="100" height="25"/>
<size key="maxSize" width="100" height="25"/>
<popUpButton key="view" verticalHuggingPriority="750" id="960">
<rect key="frame" x="0.0" y="14" width="100" height="25"/>
Expand Down Expand Up @@ -835,6 +836,7 @@
<outlet property="searchBox" destination="858" id="899"/>
<outlet property="searchView" destination="849" id="890"/>
<outlet property="textView" destination="986" id="990"/>
<outlet property="textViewController" destination="561" id="xtb-sH-Drj"/>
<outlet property="window" destination="371" id="905"/>
</connections>
</customObject>
Expand Down
5 changes: 3 additions & 2 deletions Tincta/Search/TCASearchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@class TCNotificationCreator, MainWindowController;
@class TCNotificationCreator, MainWindowController, TCTextViewController;
@interface TCASearchController : NSObject {

NSRange foundRange;
Expand All @@ -30,11 +30,12 @@
@property (assign) IBOutlet NSSegmentedControl* prevNextSegmentedControl;
@property (assign) IBOutlet NSWindow* window;
@property (assign) IBOutlet MainWindowController* mainWindowController;
@property (assign) IBOutlet TCTextViewController* textViewController;

@property (assign) BOOL isActive;


- (void) scollToPoint: (NSPoint) aPoint;
- (void) scrollToPoint: (NSPoint) aPoint;
- (NSString* )unescapeString: (NSString* )aString;
- (NSString* )escapeString: (NSString* )aString;

Expand Down
15 changes: 10 additions & 5 deletions Tincta/Search/TCASearchController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


#import "TCASearchController.h"
#import "TCTextViewController.h"
#import "TCLineNumberView.h"
#import "TCNotificationCreator.h"
#import "MainWindowController.h"
#import "TCSideBarItem.h"
Expand Down Expand Up @@ -141,7 +143,7 @@ - (IBAction) search: (id) sender {
if (foundRange.location != NSNotFound) {
NSRect boundingRect = [[self.textView layoutManager] boundingRectForGlyphRange:foundRange inTextContainer:[self.textView textContainer]];
NSPoint scrollPoint = NSMakePoint(0, boundingRect.origin.y);
[self scollToPoint:scrollPoint];
[self scrollToPoint:scrollPoint];


} else {
Expand Down Expand Up @@ -220,7 +222,7 @@ - (IBAction) findNext: (id) sender {
}
NSRect boundingRect = [[self.textView layoutManager] boundingRectForGlyphRange:foundRange inTextContainer:[self.textView textContainer]];
NSPoint scrollPoint = NSMakePoint(0, boundingRect.origin.y);
[self scollToPoint:scrollPoint];
[self scrollToPoint:scrollPoint];
[self.textView showFindIndicatorForRange:foundRange];
}
}
Expand Down Expand Up @@ -274,7 +276,7 @@ - (IBAction) findPrevious: (id) sender {
} NSRect boundingRect = [[self.textView layoutManager] boundingRectForGlyphRange:foundRange inTextContainer:[self.textView textContainer]];
NSPoint scrollPoint = NSMakePoint(0, boundingRect.origin.y);

[self scollToPoint: scrollPoint];
[self scrollToPoint: scrollPoint];

[self.textView showFindIndicatorForRange:foundRange];
}
Expand All @@ -292,7 +294,7 @@ - (IBAction) jumpToSelection: (id) sender {
NSRect boundingRect = [[self.textView layoutManager] boundingRectForGlyphRange:[self.textView selectedRange] inTextContainer:[self.textView textContainer]];
NSPoint scrollPoint = NSMakePoint(0, boundingRect.origin.y);

[self scollToPoint: scrollPoint];
[self scrollToPoint: scrollPoint];
}


Expand Down Expand Up @@ -401,14 +403,17 @@ - (NSInteger) markAllOccurrences {
return numberOfMatches;
}

- (void) scollToPoint: (NSPoint) aPoint {
- (void) scrollToPoint: (NSPoint) aPoint {
NSPoint scrollPoint = aPoint;
scrollPoint.x = -self.textViewController.lineNumberView.bounds.size.width;

if (!NSPointInRect(scrollPoint, [self.textView visibleRect])) {

CGFloat maxPoint = [[self.scrollView documentView] frame].size.height - [self.scrollView visibleRect].size.height;
if (scrollPoint.y > maxPoint) {
scrollPoint.y = maxPoint;
}

[[self.scrollView contentView] scrollToPoint: scrollPoint];
[self.scrollView reflectScrolledClipView: [self.scrollView contentView]];
}
Expand Down
1 change: 1 addition & 0 deletions Tincta/TextEditor/TCTextViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- (void)textViewDidResize:(NSNotification *)aNotification;
- (void)textViewDidScroll:(NSNotification *)aNotification;
- (void)textViewDidChangeSelection:(NSNotification *)aNotification;
- (void) updateTextViewSize;

- (void)preferencesDidChange:(NSNotification *)aNotification ;
- (void) preferencesDidChangeWrapping:(NSNotification *)aNotification;
Expand Down
49 changes: 37 additions & 12 deletions Tincta/TextEditor/TCTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ - (NSString*)textViewString {

- (void)scrollTextViewToPoint:(NSPoint)aPoint {
NSPoint scrollPoint = aPoint;
CGFloat maxPoint = [[self.scrollView documentView] frame].size.height - [self.scrollView visibleRect].size.height;
if (scrollPoint.y > maxPoint) {
scrollPoint.y = maxPoint;
}
[[self.scrollView contentView] scrollToPoint: scrollPoint];
[self.scrollView reflectScrolledClipView: [self.scrollView contentView]];
CGFloat maxPoint = [[self.scrollView documentView] frame].size.height - [self.scrollView visibleRect].size.height;
if (scrollPoint.y > maxPoint) {
scrollPoint.y = maxPoint;
}
CGFloat maxX = -lineNumberView.bounds.size.width;
if (scrollPoint.x > maxX) {
scrollPoint.x = maxX;
}
[[self.scrollView contentView] scrollToPoint: scrollPoint];
[self.scrollView reflectScrolledClipView: [self.scrollView contentView]];
}

- (NSPoint)textViewScrollPoint {
Expand Down Expand Up @@ -256,7 +260,8 @@ - (void)goToLine:(NSInteger)aLine {
TCTextStorage* ts = (TCTextStorage*)[self.textView textStorage];
NSRange lineRange = [ts lineRangeOfLine:aLine];
NSRect boundingRect = [[self.textView layoutManager] boundingRectForGlyphRange:lineRange inTextContainer:[self.textView textContainer]];
NSPoint scrollPoint = NSMakePoint(0, boundingRect.origin.y);
CGFloat lineNumberWidth = lineNumberView.frame.size.width;
NSPoint scrollPoint = NSMakePoint(-lineNumberWidth, boundingRect.origin.y);
[self scrollTextViewToPoint:scrollPoint];
}

Expand Down Expand Up @@ -415,8 +420,11 @@ - (IBAction)changeSpacesToTabs:(id)sender {
#pragma mark -
#pragma mark helpers



- (void)setLineWrapping:(BOOL)doWrap {
[self scrollTextViewToPoint:NSZeroPoint];
CGFloat lineNumberWidth = lineNumberView.frame.size.width;
[self scrollTextViewToPoint:NSMakePoint(0, 0)];
[self.textView setSelectedRange:NSMakeRange(0, 0)];
[self.scrollView setHasVerticalScroller:YES];
[self.scrollView setAutohidesScrollers:YES];
Expand All @@ -425,7 +433,7 @@ - (void)setLineWrapping:(BOOL)doWrap {
[[self.textView textContainer] setWidthTracksTextView:NO];
[[self.textView textContainer] setContainerSize: NSMakeSize(FLT_MAX, FLT_MAX)];
[self.scrollView setHasHorizontalScroller:YES];

} else {
BOOL modfiedBackup = selectedSideBarItem.isModified;
BOOL dirtyBackup = selectedSideBarItem.isDirty;
Expand All @@ -440,11 +448,11 @@ - (void)setLineWrapping:(BOOL)doWrap {
//////

[[self.textView textContainer] setWidthTracksTextView:YES];

NSSize newSize = NSMakeSize([self.scrollView documentVisibleRect].size.width, FLT_MAX);
NSSize newSize = NSMakeSize([self.scrollView documentVisibleRect].size.width - lineNumberWidth, FLT_MAX);
[[self.textView textContainer] setContainerSize: newSize];
[self.scrollView setHasHorizontalScroller:NO];

//////
[self setTextViewString: textBackup];
[syntaxColoring setSyntaxDefinitionByName:syntaxBackup];
Expand All @@ -460,6 +468,22 @@ - (void)setLineWrapping:(BOOL)doWrap {
[self invalidateAllLineNumbers];
}

- (void) updateTextViewSize {
CGFloat lineNumberWidth = lineNumberView.frame.size.width;

if ([TCADefaultsHelper getNotWrapLines]) {
[[self.textView textContainer] setWidthTracksTextView:NO];
[[self.textView textContainer] setContainerSize: NSMakeSize(FLT_MAX, FLT_MAX)];
[self.scrollView setHasHorizontalScroller:YES];

} else {
[[self.textView textContainer] setWidthTracksTextView:YES];

NSSize newSize = NSMakeSize([self.scrollView documentVisibleRect].size.width - lineNumberWidth, FLT_MAX);
[[self.textView textContainer] setContainerSize: newSize];
[self.scrollView setHasHorizontalScroller:NO];
}
}

- (void)invalidateAllLineNumbers {
//lineNumberView.lineWraps = nil;
Expand Down Expand Up @@ -511,6 +535,7 @@ - (void)layoutManager:(NSLayoutManager *)aLayoutManager didCompleteLayoutForText
[self scrollTextViewToPoint:selectedSideBarItem.scrollPoint];
needsScrolling = NO;
}
[self updateTextViewSize];
}

- (NSRange)textView:(NSTextView *)aTextView willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange {
Expand Down
16 changes: 8 additions & 8 deletions Tincta/Tincta-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>ATSApplicationFontsPath</key>
<string>Fonts</string>
<key>UIAppFonts</key>
<array>
<string>iconmonstr-iconic-font.ttf</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -62,11 +56,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>TCTA</string>
<key>CFBundleVersion</key>
<string>3200</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand All @@ -77,6 +71,12 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>UIAppFonts</key>
<array>
<string>iconmonstr-iconic-font.ttf</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
Expand Down

0 comments on commit 9d9b427

Please sign in to comment.