mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-03-13 14:13:02 +00:00
put timer delays in constants; run highlighting on a timer too
This commit is contained in:
parent
52539893eb
commit
2c1c01f807
4 changed files with 36 additions and 29 deletions
|
@ -34,6 +34,9 @@
|
||||||
|
|
||||||
#import <AppKit/NSFont.h>
|
#import <AppKit/NSFont.h>
|
||||||
|
|
||||||
|
#define PARENTHESIS_HL_DELAY 0.1
|
||||||
|
#define STATUS_LINE_UPDATE_DELAY 0.1
|
||||||
|
|
||||||
@implementation PCEditor (UInterface)
|
@implementation PCEditor (UInterface)
|
||||||
|
|
||||||
- (void)_createWindow
|
- (void)_createWindow
|
||||||
|
@ -177,6 +180,7 @@
|
||||||
if (_highlightSyntax)
|
if (_highlightSyntax)
|
||||||
{
|
{
|
||||||
[ev createSyntaxHighlighterForFileType:[_path pathExtension]];
|
[ev createSyntaxHighlighterForFileType:[_path pathExtension]];
|
||||||
|
[[ev textStorage] setFont:[ev editorFont]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[ev setMinSize:NSMakeSize(0, 0)];
|
[ev setMinSize:NSMakeSize(0, 0)];
|
||||||
|
@ -1006,7 +1010,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange
|
||||||
lsTimer = nil;
|
lsTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
lsTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
|
lsTimer = [NSTimer scheduledTimerWithTimeInterval:STATUS_LINE_UPDATE_DELAY
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(computeCurrentLineFromTimer:)
|
selector:@selector(computeCurrentLineFromTimer:)
|
||||||
userInfo:object
|
userInfo:object
|
||||||
|
@ -1034,7 +1038,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange
|
||||||
phlTimer = nil;
|
phlTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
phlTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
|
phlTimer = [NSTimer scheduledTimerWithTimeInterval:PARENTHESIS_HL_DELAY
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(computeNewParenthesisNestingFromTimer:)
|
selector:@selector(computeNewParenthesisNestingFromTimer:)
|
||||||
userInfo:sender
|
userInfo:sender
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
Interface declaration of the EditorTextView class for the
|
Interface declaration of the EditorTextView class for the
|
||||||
ProjectManager application.
|
ProjectManager application.
|
||||||
|
|
||||||
Copyright (C) 2005-2016 Free Software Foundation
|
Copyright (C) 2005-2021 Free Software Foundation
|
||||||
Saso Kiselkov
|
Saso Kiselkov
|
||||||
Riccardo Mottola
|
Riccardo Mottola
|
||||||
|
|
||||||
|
@ -30,11 +30,13 @@
|
||||||
@class NSColor;
|
@class NSColor;
|
||||||
@class PCEditor;
|
@class PCEditor;
|
||||||
@class SyntaxHighlighter;
|
@class SyntaxHighlighter;
|
||||||
|
@class NSTimer;
|
||||||
|
|
||||||
@interface PCEditorView : NSTextView <CodeEditorView>
|
@interface PCEditorView : NSTextView <CodeEditorView>
|
||||||
{
|
{
|
||||||
PCEditor *editor;
|
PCEditor *editor;
|
||||||
SyntaxHighlighter *highlighter;
|
SyntaxHighlighter *highlighter;
|
||||||
|
NSTimer *hlTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSFont *)defaultEditorFont;
|
+ (NSFont *)defaultEditorFont;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
Implementation of the PCEditorView class for the
|
Implementation of the PCEditorView class for the
|
||||||
ProjectManager application.
|
ProjectManager application.
|
||||||
|
|
||||||
Copyright (C) 2005-2020 Free Software Foundation
|
Copyright (C) 2005-2021 Free Software Foundation
|
||||||
Saso Kiselkov
|
Saso Kiselkov
|
||||||
Serg Stoyan
|
Serg Stoyan
|
||||||
Riccardo Mottola
|
Riccardo Mottola
|
||||||
|
@ -47,6 +47,8 @@
|
||||||
#import "LineJumper.h"
|
#import "LineJumper.h"
|
||||||
#import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h"
|
#import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h"
|
||||||
|
|
||||||
|
#define SYNTAX_HL_DELAY 0.05
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the indenting offset of the last line before the passed
|
* Computes the indenting offset of the last line before the passed
|
||||||
* start offset containg text in the passed string, e.g.
|
* start offset containg text in the passed string, e.g.
|
||||||
|
@ -475,17 +477,40 @@ static int ComputeIndentingOffset(NSString * string, NSUInteger start)
|
||||||
if (highlighter)
|
if (highlighter)
|
||||||
{
|
{
|
||||||
NSRange drawnRange;
|
NSRange drawnRange;
|
||||||
|
NSValue *timerInfo;
|
||||||
|
|
||||||
drawnRange = [[self layoutManager]
|
drawnRange = [[self layoutManager]
|
||||||
glyphRangeForBoundingRect:r inTextContainer:[self textContainer]];
|
glyphRangeForBoundingRect:r inTextContainer:[self textContainer]];
|
||||||
drawnRange = [[self layoutManager] characterRangeForGlyphRange:drawnRange
|
drawnRange = [[self layoutManager] characterRangeForGlyphRange:drawnRange
|
||||||
actualGlyphRange:NULL];
|
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];
|
[super drawRect:r];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)highlightRangeFromTimer:(NSTimer *)t
|
||||||
|
{
|
||||||
|
NSRange range;
|
||||||
|
|
||||||
|
range = [(NSValue *)[t userInfo] rangeValue];
|
||||||
|
hlTimer = nil;
|
||||||
|
[highlighter highlightRange:range];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)createSyntaxHighlighterForFileType:(NSString *)fileType
|
- (void)createSyntaxHighlighterForFileType:(NSString *)fileType
|
||||||
{
|
{
|
||||||
ASSIGN(highlighter,
|
ASSIGN(highlighter,
|
||||||
|
|
|
@ -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)
|
@interface SyntaxHighlighter (Private)
|
||||||
|
|
||||||
- (void) fixUpContextsInRange: (NSRange) r;
|
- (void) fixUpContextsInRange: (NSRange) r;
|
||||||
|
|
Loading…
Reference in a new issue