mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-02-11 08:21:00 +00:00
merge from master
This commit is contained in:
commit
cf1b7a3215
5 changed files with 108 additions and 205 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2021-11-26 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Modules/Editors/ProjectCenter/PCEditor.m
|
||||
Do not send double computeNewParenthesisNesting: on key pressed.
|
||||
Furthermore, use a timer so that in case of rapid re-computing
|
||||
it gets invalidated before and only calculated at the last event.
|
||||
|
||||
2021-10-19 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Modules/Editors/ProjectCenter/PCEditorView.h
|
||||
* Modules/Editors/ProjectCenter/PCEditorView.m
|
||||
Remove insertText and handle keys through appropriate methods (inserTab, cancelOperation)
|
||||
|
||||
2021-08-18 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Modules/Editors/ProjectCenter/PCEditor.m
|
||||
|
|
|
@ -76,21 +76,11 @@
|
|||
NSColor *highlightColor;
|
||||
NSColor *backgroundColor;
|
||||
NSColor *readOnlyColor;
|
||||
NSColor *textBackground;
|
||||
|
||||
// location of the highlit delimiter character
|
||||
unsigned int highlitCharacterLocation;
|
||||
NSColor *textBackgroundColor;
|
||||
|
||||
// is YES if we are currently highlighting a delimiter character
|
||||
// otherwise NO
|
||||
BOOL isCharacterHighlit;
|
||||
int highlited_chars[2];
|
||||
|
||||
// the stored color and font attributes of the highlit character, so
|
||||
// that they can be restored later on when the character is un-highlit
|
||||
NSColor *previousFGColor;
|
||||
NSColor *previousBGColor;
|
||||
NSColor *previousFont;
|
||||
// location of the highlighted delimiter characters
|
||||
// NSNotFound means not set
|
||||
NSUInteger highlighted_chars[2];
|
||||
|
||||
// This is used to protect that -textViewDidChangeSelection: invocations
|
||||
// don't do anything when the text view changing, because this causes
|
||||
|
@ -98,6 +88,9 @@
|
|||
// of this method.
|
||||
BOOL editorTextViewIsPressingKey;
|
||||
|
||||
// Slightly delay drawing of highlit parentheses
|
||||
NSTimer *phlTimer;
|
||||
|
||||
// keep one undo manager for the editor
|
||||
NSUndoManager *undoManager;
|
||||
}
|
||||
|
@ -154,7 +147,7 @@
|
|||
@interface PCEditor (Parenthesis)
|
||||
|
||||
- (void)unhighlightCharacter: (NSTextView *)editorView;
|
||||
- (void)highlightCharacterAt:(NSUInteger)location inEditor: (NSTextView *)editorView;
|
||||
- (void)highlightCharacterPair: (NSTextView *)editorView;
|
||||
- (void)computeNewParenthesisNesting: (NSTextView *)editorView;
|
||||
|
||||
@end
|
||||
|
|
|
@ -168,7 +168,7 @@
|
|||
RELEASE(lm);
|
||||
|
||||
ev = [[PCEditorView alloc] initWithFrame:fr textContainer:tc];
|
||||
[ev setBackgroundColor:textBackground];
|
||||
[ev setBackgroundColor:textBackgroundColor];
|
||||
[ev setTextColor:textColor];
|
||||
[ev setEditor:self];
|
||||
if (_highlightSyntax)
|
||||
|
@ -207,18 +207,14 @@
|
|||
// Activate undo
|
||||
[ev setAllowsUndo: YES];
|
||||
|
||||
[ev setDelegate:self];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(textDidChange:)
|
||||
name:NSTextDidChangeNotification
|
||||
object:ev];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(textViewDidChangeSelection:)
|
||||
name:NSTextViewDidChangeSelectionNotification
|
||||
object:ev];
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
|
@ -254,14 +250,9 @@
|
|||
ASSIGN(textColor, [NSColor blackColor]);
|
||||
ASSIGN(backgroundColor, [NSColor whiteColor]);
|
||||
ASSIGN(readOnlyColor, [NSColor lightGrayColor]);
|
||||
|
||||
previousFGColor = nil;
|
||||
previousBGColor = nil;
|
||||
previousFont = nil;
|
||||
|
||||
isCharacterHighlit = NO;
|
||||
highlited_chars[0] = -1;
|
||||
highlited_chars[1] = -1;
|
||||
highlighted_chars[0] = NSNotFound;
|
||||
highlighted_chars[1] = NSNotFound;
|
||||
|
||||
undoManager = [[NSUndoManager alloc] init];
|
||||
}
|
||||
|
@ -344,17 +335,17 @@
|
|||
NSColor *col;
|
||||
|
||||
col = [prefs colorForKey:EditorBackgroundColor defaultValue:backgroundColor];
|
||||
textBackground = col;
|
||||
textBackgroundColor = col;
|
||||
}
|
||||
else
|
||||
{
|
||||
textBackground = readOnlyColor;
|
||||
textBackgroundColor = readOnlyColor;
|
||||
}
|
||||
|
||||
textColor = [prefs colorForKey:EditorForegroundColor defaultValue:textColor];
|
||||
|
||||
[attributes setObject:font forKey:NSFontAttributeName];
|
||||
[attributes setObject:textBackground forKey:NSBackgroundColorAttributeName];
|
||||
[attributes setObject:textBackgroundColor forKey:NSBackgroundColorAttributeName];
|
||||
[attributes setObject:textColor forKey:NSForegroundColorAttributeName];
|
||||
[attributes setObject:[NSNumber numberWithInt: 0] // disable ligatures
|
||||
forKey:NSLigatureAttributeName];
|
||||
|
@ -980,12 +971,29 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (NSRange)textView:(NSTextView *)textView
|
||||
willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange
|
||||
toCharacterRange:(NSRange)newSelectedCharRange
|
||||
{
|
||||
NSDebugLog(@"Will change selection from %@ to %@", NSStringFromRange(oldSelectedCharRange), NSStringFromRange(newSelectedCharRange));
|
||||
|
||||
if (editorTextViewIsPressingKey == NO)
|
||||
{
|
||||
// unhighlight also invalidates old locations
|
||||
if (textView == _intEditorView || textView == _extEditorView)
|
||||
[self unhighlightCharacter: textView];
|
||||
}
|
||||
|
||||
return newSelectedCharRange;
|
||||
}
|
||||
|
||||
- (void)textViewDidChangeSelection:(NSNotification *)notification
|
||||
{
|
||||
id object;
|
||||
|
||||
object = [notification object];
|
||||
|
||||
NSDebugLog(@"received textViewDidChangeSelection notification");
|
||||
// calculate current line
|
||||
if ([object isKindOfClass:[NSTextView class]])
|
||||
{
|
||||
|
@ -1019,7 +1027,7 @@
|
|||
|
||||
selLine = nlCount + 1;
|
||||
}
|
||||
NSLog(@"%u corresponds to %u", selection.location, selLine);
|
||||
NSLog(@"%u corresponds to %u", (unsigned int)selection.location, (unsigned int)selLine);
|
||||
if (selLine != NSNotFound)
|
||||
{
|
||||
[_intStatusField setStringValue: [NSString stringWithFormat:@"%u", (unsigned)selLine]];
|
||||
|
@ -1041,7 +1049,19 @@
|
|||
- (void)editorTextViewDidPressKey:sender
|
||||
{
|
||||
if (sender == _intEditorView || sender == _extEditorView)
|
||||
[self computeNewParenthesisNesting: sender];
|
||||
{
|
||||
if (nil != phlTimer)
|
||||
{
|
||||
[phlTimer invalidate];
|
||||
phlTimer = nil;
|
||||
}
|
||||
|
||||
phlTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
|
||||
target:self
|
||||
selector:@selector(computeNewParenthesisNestingFromTimer:)
|
||||
userInfo:sender
|
||||
repeats:NO];
|
||||
}
|
||||
else
|
||||
NSLog(@"PCEditor: unexpected sender");
|
||||
|
||||
|
@ -1382,112 +1402,56 @@ NSUInteger FindDelimiterInString(NSString * string,
|
|||
|
||||
- (void)unhighlightCharacter: (NSTextView *)editorView
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
NSTextStorage *textStorage = [editorView textStorage];
|
||||
|
||||
[textStorage beginEditing];
|
||||
|
||||
// if (isCharacterHighlit)
|
||||
for (i = 0; i < 2 && highlited_chars[i] != -1; i++)
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
NSRange r = NSMakeRange(highlited_chars[i], 1);
|
||||
// NSRange r = NSMakeRange(highlitCharacterLocation, i);
|
||||
if (highlighted_chars[i] == NSNotFound)
|
||||
continue;
|
||||
|
||||
NSRange r = NSMakeRange(highlighted_chars[i], 1);
|
||||
|
||||
isCharacterHighlit = NO;
|
||||
[textStorage addAttribute:NSBackgroundColorAttributeName
|
||||
value:textBackgroundColor
|
||||
range:r];
|
||||
|
||||
// restore the character's color and font attributes
|
||||
if (previousFont != nil)
|
||||
{
|
||||
[textStorage addAttribute:NSFontAttributeName
|
||||
value:previousFont
|
||||
range:r];
|
||||
}
|
||||
else
|
||||
{
|
||||
[textStorage removeAttribute:NSFontAttributeName range:r];
|
||||
}
|
||||
|
||||
if (previousFGColor != nil)
|
||||
{
|
||||
[textStorage addAttribute:NSForegroundColorAttributeName
|
||||
value:previousFGColor
|
||||
range:r];
|
||||
}
|
||||
else
|
||||
{
|
||||
[textStorage removeAttribute:NSForegroundColorAttributeName
|
||||
range:r];
|
||||
}
|
||||
|
||||
if (previousBGColor != nil)
|
||||
{
|
||||
[textStorage addAttribute:NSBackgroundColorAttributeName
|
||||
value:previousBGColor
|
||||
range:r];
|
||||
}
|
||||
else
|
||||
{
|
||||
[textStorage removeAttribute:NSBackgroundColorAttributeName
|
||||
range:r];
|
||||
}
|
||||
|
||||
highlited_chars[i] = -1;
|
||||
highlighted_chars[i] = NSNotFound;
|
||||
}
|
||||
|
||||
[textStorage endEditing];
|
||||
}
|
||||
|
||||
- (void)highlightCharacterAt:(NSUInteger)location inEditor: (NSTextView *)editorView
|
||||
- (void)highlightCharacterPair:(NSTextView *)editorView
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
NSTextStorage *textStorage = [editorView textStorage];
|
||||
|
||||
for (i = 0; i < 2 && highlited_chars[i] != -1; i++) {};
|
||||
[textStorage beginEditing];
|
||||
|
||||
// if (isCharacterHighlit == NO)
|
||||
if (i < 2)
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
NSTextStorage *textStorage = [editorView textStorage];
|
||||
NSRange r = NSMakeRange(location, 1);
|
||||
NSRange tmp;
|
||||
if (highlighted_chars[i] == NSNotFound)
|
||||
continue;
|
||||
|
||||
// NSLog(@"highlight");
|
||||
NSRange r = NSMakeRange(highlighted_chars[i], 1);
|
||||
|
||||
// highlitCharacterLocation = location;
|
||||
highlited_chars[i] = location;
|
||||
|
||||
isCharacterHighlit = YES;
|
||||
NSAssert(textStorage, @"textstorage can't be nil");
|
||||
[textStorage beginEditing];
|
||||
|
||||
// store the previous character's attributes
|
||||
ASSIGN(previousFGColor,
|
||||
[textStorage attribute:NSForegroundColorAttributeName
|
||||
atIndex:location
|
||||
effectiveRange:&tmp]);
|
||||
ASSIGN(previousBGColor,
|
||||
[textStorage attribute:NSBackgroundColorAttributeName
|
||||
atIndex:location
|
||||
effectiveRange:&tmp]);
|
||||
ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName
|
||||
atIndex:location
|
||||
effectiveRange:&tmp]);
|
||||
|
||||
[textStorage addAttribute:NSFontAttributeName
|
||||
value:highlightFont
|
||||
range:r];
|
||||
[textStorage addAttribute:NSBackgroundColorAttributeName
|
||||
value:highlightColor
|
||||
range:r];
|
||||
/* [textStorage addAttribute:NSForegroundColorAttributeName
|
||||
value:highlightColor
|
||||
range:r];
|
||||
|
||||
[textStorage removeAttribute:NSBackgroundColorAttributeName
|
||||
range:r];*/
|
||||
|
||||
[textStorage endEditing];
|
||||
}
|
||||
[textStorage endEditing];
|
||||
}
|
||||
|
||||
- (void)computeNewParenthesisNestingFromTimer:(NSTimer *)timer
|
||||
{
|
||||
phlTimer = nil;
|
||||
[self computeNewParenthesisNesting:[timer userInfo]];
|
||||
}
|
||||
|
||||
- (void)computeNewParenthesisNesting: (NSTextView *)editorView
|
||||
|
@ -1503,7 +1467,8 @@ NSUInteger FindDelimiterInString(NSString * string,
|
|||
NSAssert(editorView, @"computeNewParenthesis: editorView is nil");
|
||||
selectedRange = [editorView selectedRange];
|
||||
|
||||
// make sure we un-highlight a previously highlit delimiter
|
||||
// make sure we un-highlit a previously highlit delimiter
|
||||
// should normally be already un-highlit by will change notif.
|
||||
[self unhighlightCharacter :editorView];
|
||||
|
||||
// if we have a character at the selected location, check
|
||||
|
@ -1534,8 +1499,9 @@ NSUInteger FindDelimiterInString(NSString * string,
|
|||
// and in case a delimiter is found, highlight it
|
||||
if (result != NSNotFound)
|
||||
{
|
||||
[self highlightCharacterAt:selectedRange.location inEditor:editorView];
|
||||
[self highlightCharacterAt:result inEditor:editorView];
|
||||
highlighted_chars[0] = selectedRange.location;
|
||||
highlighted_chars[1] = result;
|
||||
[self highlightCharacterPair :editorView];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
|
||||
- (void)createSyntaxHighlighterForFileType:(NSString *)fileType;
|
||||
|
||||
- (void)insertText:text;
|
||||
|
||||
- (NSRect)selectionRect;
|
||||
|
||||
// =====
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
* @return The ammount of spaces the last line containing text is offset
|
||||
* from it's start.
|
||||
*/
|
||||
static int ComputeIndentingOffset(NSString * string, unsigned int start)
|
||||
static int ComputeIndentingOffset(NSString * string, NSUInteger start)
|
||||
{
|
||||
SEL sel = @selector(characterAtIndex:);
|
||||
unichar (* charAtIndex)(NSString *, SEL, unsigned int) =
|
||||
|
@ -498,96 +498,29 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
|
|||
[highlighter setBoldItalicFont: [self editorBoldItalicFont]];
|
||||
}
|
||||
|
||||
- (void)insertText:text
|
||||
- (void) cancelOperation: (id)sender
|
||||
{
|
||||
/* NOTE: On Windows we ensure to get a string in UTF-8 encoding. The problem
|
||||
* is the highlighter that don't use a consistent codification causing a
|
||||
* problem on Windows platform. Anyway, the plugin for Gemas editor works
|
||||
* better and don't show this problem.
|
||||
*/
|
||||
if ([text isKindOfClass:[NSString class]])
|
||||
{
|
||||
NSString * string = text;
|
||||
// ignore ESC char
|
||||
}
|
||||
|
||||
if ([text characterAtIndex:0] == 27)
|
||||
{
|
||||
NSLog(@"ESC key pressed. Ignoring it");
|
||||
return;
|
||||
}
|
||||
- (void) insertNewline: (id)sender
|
||||
{
|
||||
NSInteger location = [self selectedRange].location;
|
||||
int offset = ComputeIndentingOffset([self string], location);
|
||||
char buf[offset+2];
|
||||
|
||||
if ([string isEqualToString:@"\n"])
|
||||
{
|
||||
/* if ([[NSUserDefaults standardUserDefaults]
|
||||
boolForKey:@"ReturnDoesAutoindent"])
|
||||
{*/
|
||||
int location = [self selectedRange].location;
|
||||
int offset = ComputeIndentingOffset([self string], location);
|
||||
char *buf;
|
||||
buf[0] = '\n';
|
||||
memset(&buf[1], ' ', offset);
|
||||
buf[offset+1] = '\0';
|
||||
|
||||
buf = (char *) malloc((offset + 2) * sizeof(unichar));
|
||||
buf[0] = '\n';
|
||||
memset(&buf[1], ' ', offset);
|
||||
buf[offset+1] = '\0';
|
||||
// let's use UTF8 to be on the safe side
|
||||
[self insertText: [NSString stringWithCString: buf
|
||||
encoding: NSUTF8StringEncoding]];
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
[super insertText:[NSString stringWithCString: buf
|
||||
encoding: NSUTF8StringEncoding]];
|
||||
#else
|
||||
[super insertText:[NSString stringWithCString:buf]];
|
||||
#endif
|
||||
free(buf);
|
||||
/* }
|
||||
else
|
||||
{
|
||||
[super insertText:text];
|
||||
}*/
|
||||
}
|
||||
else if ([string isEqualToString:@"\t"])
|
||||
{
|
||||
[self performIndentation];
|
||||
/* switch ([[NSUserDefaults standardUserDefaults]
|
||||
integerForKey:@"TabConversion"])
|
||||
{
|
||||
case 0: // no conversion
|
||||
[super insertText:text];
|
||||
break;
|
||||
case 1: // 2 spaces
|
||||
[super insertText:@" "];
|
||||
break;
|
||||
case 2: // 4 spaces
|
||||
[super insertText:@" "];
|
||||
break;
|
||||
case 3: // 8 spaces
|
||||
[super insertText:@" "];
|
||||
break;
|
||||
case 4: // aligned to tab boundaries of 2 spaces long tabs
|
||||
[self insertSpaceFillAlignedAtTabsOfSize:2];
|
||||
break;
|
||||
case 5: // aligned to tab boundaries of 4 spaces long tabs
|
||||
[self insertSpaceFillAlignedAtTabsOfSize:4];
|
||||
break;
|
||||
case 6: // aligned to tab boundaries of 8 spaces long tabs
|
||||
[self insertSpaceFillAlignedAtTabsOfSize:8];
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
[super insertText: [NSString stringWithCString: [text UTF8String]]];
|
||||
#else
|
||||
[super insertText: text];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
[super insertText: [NSString stringWithCString: [text UTF8String]]];
|
||||
#else
|
||||
[super insertText: text];
|
||||
#endif
|
||||
}
|
||||
- (void) insertTab: (id)sender
|
||||
{
|
||||
[self performIndentation];
|
||||
}
|
||||
|
||||
/* This extra change tracking is required in order to inform the document
|
||||
|
|
Loading…
Reference in a new issue