diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index d49313d..9a4a201 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -34,6 +34,9 @@ #import +#define PARENTHESIS_HL_DELAY 0.1 +#define STATUS_LINE_UPDATE_DELAY 0.1 + @implementation PCEditor (UInterface) - (void)_createWindow @@ -177,6 +180,7 @@ if (_highlightSyntax) { [ev createSyntaxHighlighterForFileType:[_path pathExtension]]; + [[ev textStorage] setFont:[ev editorFont]]; } [ev setMinSize:NSMakeSize(0, 0)]; @@ -1006,7 +1010,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange lsTimer = nil; } - lsTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 + lsTimer = [NSTimer scheduledTimerWithTimeInterval:STATUS_LINE_UPDATE_DELAY target:self selector:@selector(computeCurrentLineFromTimer:) userInfo:object @@ -1034,7 +1038,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange phlTimer = nil; } - phlTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 + phlTimer = [NSTimer scheduledTimerWithTimeInterval:PARENTHESIS_HL_DELAY target:self selector:@selector(computeNewParenthesisNestingFromTimer:) userInfo:sender diff --git a/Modules/Editors/ProjectCenter/PCEditorView.h b/Modules/Editors/ProjectCenter/PCEditorView.h index ac22c9d..adbe9b0 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.h +++ b/Modules/Editors/ProjectCenter/PCEditorView.h @@ -4,7 +4,7 @@ Interface declaration of the EditorTextView class for the ProjectManager application. - Copyright (C) 2005-2016 Free Software Foundation + Copyright (C) 2005-2021 Free Software Foundation Saso Kiselkov Riccardo Mottola @@ -30,11 +30,13 @@ @class NSColor; @class PCEditor; @class SyntaxHighlighter; +@class NSTimer; @interface PCEditorView : NSTextView { PCEditor *editor; SyntaxHighlighter *highlighter; + NSTimer *hlTimer; } + (NSFont *)defaultEditorFont; diff --git a/Modules/Editors/ProjectCenter/PCEditorView.m b/Modules/Editors/ProjectCenter/PCEditorView.m index 1785dcf..65caa73 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.m +++ b/Modules/Editors/ProjectCenter/PCEditorView.m @@ -4,7 +4,7 @@ Implementation of the PCEditorView class for the ProjectManager application. - Copyright (C) 2005-2020 Free Software Foundation + Copyright (C) 2005-2021 Free Software Foundation Saso Kiselkov Serg Stoyan Riccardo Mottola @@ -47,6 +47,8 @@ #import "LineJumper.h" #import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h" +#define SYNTAX_HL_DELAY 0.05 + /** * Computes the indenting offset of the last line before the passed * start offset containg text in the passed string, e.g. @@ -475,17 +477,40 @@ static int ComputeIndentingOffset(NSString * string, NSUInteger start) if (highlighter) { NSRange drawnRange; + NSValue *timerInfo; drawnRange = [[self layoutManager] glyphRangeForBoundingRect:r inTextContainer:[self textContainer]]; drawnRange = [[self layoutManager] characterRangeForGlyphRange:drawnRange actualGlyphRange:NULL]; - [highlighter highlightRange:drawnRange]; + + timerInfo = [NSValue valueWithRange:drawnRange]; + + if (nil != hlTimer) + { + [hlTimer invalidate]; + hlTimer = nil; + } + + hlTimer = [NSTimer scheduledTimerWithTimeInterval:SYNTAX_HL_DELAY + target:self + selector:@selector(highlightRangeFromTimer:) + userInfo:timerInfo + repeats:NO]; } [super drawRect:r]; } +- (void)highlightRangeFromTimer:(NSTimer *)t +{ + NSRange range; + + range = [(NSValue *)[t userInfo] rangeValue]; + hlTimer = nil; + [highlighter highlightRange:range]; +} + - (void)createSyntaxHighlighterForFileType:(NSString *)fileType { ASSIGN(highlighter, diff --git a/Modules/Editors/ProjectCenter/SyntaxHighlighter.m b/Modules/Editors/ProjectCenter/SyntaxHighlighter.m index aa0d8e5..6906d4c 100644 --- a/Modules/Editors/ProjectCenter/SyntaxHighlighter.m +++ b/Modules/Editors/ProjectCenter/SyntaxHighlighter.m @@ -117,30 +117,6 @@ RangeOfWordInString(NSString * string, NSRange startRange) } } -static inline BOOL -LocateString(NSString * str, - unichar * buf, - NSUInteger length, - NSUInteger offset) -{ - NSUInteger i, n; - - for (i = 0, n = [str length]; i < n; i++) - { - if (i >= length) - { - return NO; - } - - if (buf[i + offset] != [str characterAtIndex: i]) - { - return NO; - } - } - - return YES; -} - @interface SyntaxHighlighter (Private) - (void) fixUpContextsInRange: (NSRange) r;