put timer delays in constants; run highlighting on a timer too

This commit is contained in:
Riccardo Mottola 2021-12-01 01:37:45 +01:00
parent 52539893eb
commit 2c1c01f807
4 changed files with 36 additions and 29 deletions

View file

@ -34,6 +34,9 @@
#import <AppKit/NSFont.h>
#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

View file

@ -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 <CodeEditorView>
{
PCEditor *editor;
SyntaxHighlighter *highlighter;
NSTimer *hlTimer;
}
+ (NSFont *)defaultEditorFont;

View file

@ -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,

View file

@ -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;