Use updateRuler method for line number view update

This commit is contained in:
1024jp 2015-08-09 17:39:37 +09:00
parent 820b60e61d
commit 1c4dcd206f
7 changed files with 19 additions and 110 deletions

View File

@ -247,7 +247,7 @@ a
### Additions/Changes
a
- Drop support for __OS X Lion.__
- Migrate document drawer to sidebar style.
- Add “show document inspector” option to preferences.

View File

@ -200,7 +200,6 @@
CEDefaultFirstColoringDelayKey: @0.3f,
CEDefaultSecondColoringDelayKey: @0.7f,
CEDefaultAutoCompletionDelayKey: @0.25,
CEDefaultLineNumUpdateIntervalKey: @0.12f,
CEDefaultInfoUpdateIntervalKey: @0.2f,
CEDefaultIncompatibleCharIntervalKey: @0.42f,
CEDefaultOutlineMenuIntervalKey: @0.37f,

View File

@ -43,8 +43,6 @@
@property (nonatomic, nonnull) CEEditorScrollView *scrollView;
@property (nonatomic, nonnull) NSTextStorage *textStorage;
@property (nonatomic, nullable) NSTimer *lineNumUpdateTimer;
@property (nonatomic) BOOL highlightsCurrentLine;
@property (nonatomic) NSInteger lastCursorLocation;
@ -158,7 +156,6 @@
- (void)dealloc
// ------------------------------------------------------
{
[self stopUpdateLineNumberTimer];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_textStorage removeLayoutManager:[_textView layoutManager]];
@ -224,8 +221,6 @@
if (isVertical) {
[textView setLayoutOrientation:NSTextLayoutOrientationVertical];
}
[[self scrollView] invalidateLineNumber];
}
@ -569,21 +564,6 @@
}
// ------------------------------------------------------
/// textStorage
- (void)setTextStorage:(NSTextStorage *)textStorage
// ------------------------------------------------------
{
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateLineNumber)
name:NSTextStorageDidProcessEditingNotification
object:textStorage];
_textStorage = textStorage;
}
// ------------------------------------------------------
///
- (void)updateOutlineMenuSelection
@ -607,49 +587,6 @@
}
// ------------------------------------------------------
///
- (void)updateLineNumber
// ------------------------------------------------------
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//
NSTimeInterval lineNumUpdateInterval = [defaults doubleForKey:CEDefaultLineNumUpdateIntervalKey];
if ([self lineNumUpdateTimer]) {
[[self lineNumUpdateTimer] setFireDate:[NSDate dateWithTimeIntervalSinceNow:lineNumUpdateInterval]];
} else {
[self setLineNumUpdateTimer:[NSTimer scheduledTimerWithTimeInterval:lineNumUpdateInterval
target:self
selector:@selector(updateLineNumberWithTimer:)
userInfo:nil
repeats:NO]];
}
}
// ------------------------------------------------------
///
- (void)updateLineNumberWithTimer:(nonnull NSTimer *)timer
// ------------------------------------------------------
{
[self stopUpdateLineNumberTimer];
[[self scrollView] invalidateLineNumber];
}
// ------------------------------------------------------
///
- (void)stopUpdateLineNumberTimer
// ------------------------------------------------------
{
if ([self lineNumUpdateTimer]) {
[[self lineNumUpdateTimer] invalidate];
[self setLineNumUpdateTimer:nil];
}
}
// ------------------------------------------------------
///
- (void)highlightCurrentLine

View File

@ -76,12 +76,6 @@ static const NSString *LineNumberFontName;
self = [super initWithScrollView:scrollView orientation:orientation];
if (self) {
[self setClientView:[scrollView documentView]];
// update line number on scroll view resize for text wrapping change
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(invalidateLineNumber)
name:NSViewFrameDidChangeNotification
object:scrollView];
}
return self;
}
@ -98,15 +92,6 @@ static const NSString *LineNumberFontName;
}
// ------------------------------------------------------
/// clean up
- (void)dealloc
// ------------------------------------------------------
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
// ------------------------------------------------------
/// draw background
- (void)drawRect:(NSRect)dirtyRect
@ -323,15 +308,6 @@ static const NSString *LineNumberFontName;
}
// ------------------------------------------------------
/// update line number
- (void)invalidateLineNumber
// ------------------------------------------------------
{
[self setNeedsDisplay:YES];
}
// ------------------------------------------------------
/// select lines while dragging event
- (void)selectLines:(nullable NSTimer *)timer

View File

@ -568,7 +568,6 @@ static NSPoint kTextContainerOrigin;
[self setFont:newFont];
[self setNeedsDisplayInRect:[self visibleRect] avoidAdditionalLayout:YES]; // (2009-02-14)
[self updateLineNumberAndAdjustScroll];
}
@ -949,6 +948,15 @@ static NSPoint kTextContainerOrigin;
}
// ------------------------------------------------------
/// let line number view update
- (void)updateRuler
// ------------------------------------------------------
{
[[self scrollView] invalidateLineNumber];
}
#pragma mark Protocol
@ -1118,7 +1126,12 @@ static NSPoint kTextContainerOrigin;
// redraw
NSRange range = NSMakeRange(0, [[self string] length]);
[[self layoutManager] invalidateLayoutForCharacterRange:range actualCharacterRange:nil];
[self updateLineNumberAndAdjustScroll];
// 調
[self updateRuler];
// 調
[self scrollRangeToVisible:[self selectedRange]];
}
@ -1172,7 +1185,9 @@ static NSPoint kTextContainerOrigin;
CGFloat size = (CGFloat)[[NSUserDefaults standardUserDefaults] doubleForKey:CEDefaultFontSizeKey];
[self setFont:[NSFont fontWithName:name size:size] ? : [NSFont systemFontOfSize:size]];
[self updateLineNumberAndAdjustScroll];
// 調
[self scrollRangeToVisible:[self selectedRange]];
}
@ -1529,19 +1544,6 @@ static NSPoint kTextContainerOrigin;
}
// ------------------------------------------------------
/// 調
- (void)updateLineNumberAndAdjustScroll
// ------------------------------------------------------
{
// 調
[[self scrollView] invalidateLineNumber];
// 調
[self scrollRangeToVisible:[self selectedRange]];
}
// ------------------------------------------------------
/// Pasetboard
- (void)replaceLineEndingToDocCharInPboard:(NSPasteboard *)pboard
@ -2043,9 +2045,6 @@ static NSPoint kTextContainerOrigin;
if (isSelectionVisible) {
[self scrollRangeToVisible:selectedRange];
}
// force redraw line number view
[[self scrollView] invalidateLineNumber];
}
@end

View File

@ -219,7 +219,6 @@ extern NSString *__nonnull const CEDefaultBasicColoringDelayKey;
extern NSString *__nonnull const CEDefaultFirstColoringDelayKey;
extern NSString *__nonnull const CEDefaultSecondColoringDelayKey;
extern NSString *__nonnull const CEDefaultAutoCompletionDelayKey;
extern NSString *__nonnull const CEDefaultLineNumUpdateIntervalKey;
extern NSString *__nonnull const CEDefaultInfoUpdateIntervalKey;
extern NSString *__nonnull const CEDefaultIncompatibleCharIntervalKey;
extern NSString *__nonnull const CEDefaultOutlineMenuIntervalKey;

View File

@ -218,7 +218,6 @@ NSString *__nonnull const CEDefaultBasicColoringDelayKey = @"basicColoringDelay"
NSString *__nonnull const CEDefaultFirstColoringDelayKey = @"firstColoringDelay";
NSString *__nonnull const CEDefaultSecondColoringDelayKey = @"secondColoringDelay";
NSString *__nonnull const CEDefaultAutoCompletionDelayKey = @"autoCompletionDelay";
NSString *__nonnull const CEDefaultLineNumUpdateIntervalKey = @"lineNumUpdateInterval";
NSString *__nonnull const CEDefaultInfoUpdateIntervalKey = @"infoUpdateInterval";
NSString *__nonnull const CEDefaultIncompatibleCharIntervalKey = @"incompatibleCharInterval";
NSString *__nonnull const CEDefaultOutlineMenuIntervalKey = @"outlineMenuInterval";