From 60db8c598fb42cff239a291c9a5b4429ca370fd8 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Thu, 21 Oct 2021 23:36:13 +0200 Subject: [PATCH 1/8] refactor some of the character highlighting, trying to rely only on the start-end pair of locations without old extra variables --- Modules/Editors/ProjectCenter/PCEditor.h | 10 +-- Modules/Editors/ProjectCenter/PCEditor.m | 81 ++++++++++++------------ 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 96f97f4..01799de 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -74,14 +74,10 @@ NSColor *backgroundColor; NSColor *readOnlyColor; NSColor *textBackground; - - // location of the highlit delimiter character - unsigned int highlitCharacterLocation; - // is YES if we are currently highlighting a delimiter character - // otherwise NO - BOOL isCharacterHighlit; - int highlited_chars[2]; + // location of the highlighted delimiter characters + // NSNotFound means not set + NSUInteger 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 diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 2c93504..d3e980b 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -175,18 +175,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; } @@ -227,9 +223,8 @@ previousBGColor = nil; previousFont = nil; - isCharacterHighlit = NO; - highlited_chars[0] = -1; - highlited_chars[1] = -1; + highlited_chars[0] = NSNotFound; + highlited_chars[1] = NSNotFound; undoManager = [[NSUndoManager alloc] init]; } @@ -948,6 +943,23 @@ } } +- (NSRange)textView:(NSTextView *)textView +willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange + toCharacterRange:(NSRange)newSelectedCharRange +{ + NSLog(@"Will change selection from %@ to %@", NSStringFromRange(oldSelectedCharRange), NSStringFromRange(newSelectedCharRange)); + + NSLog(@"is pressing key %d", editorTextViewIsPressingKey); + if (editorTextViewIsPressingKey == NO) + { + // unhighlight also invalidates old locations + if (textView == _intEditorView || textView == _extEditorView) + [self unhighlightCharacter: textView]; + } + + return newSelectedCharRange; +} + - (void)textViewDidChangeSelection:(NSNotification *)notification { id object; @@ -956,13 +968,11 @@ if (editorTextViewIsPressingKey == NO) { - id object; - - object = [notification object]; if (object == _intEditorView || object == _extEditorView) [self computeNewParenthesisNesting: object]; } + NSLog(@"textViewDidChangeSelection"); // calculate current line if ([object isKindOfClass:[NSTextView class]]) { @@ -1356,19 +1366,17 @@ 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++) { + if (highlited_chars[i] == NSNotFound) + continue; + NSRange r = NSMakeRange(highlited_chars[i], 1); -// NSRange r = NSMakeRange(highlitCharacterLocation, i); - - - isCharacterHighlit = NO; // restore the character's color and font attributes if (previousFont != nil) @@ -1406,45 +1414,39 @@ NSUInteger FindDelimiterInString(NSString * string, range:r]; } - highlited_chars[i] = -1; + highlited_chars[i] = NSNotFound; } [textStorage endEditing]; } -- (void)highlightCharacterAt:(NSUInteger)location inEditor: (NSTextView *)editorView +- (void)highlightCharacterPair:(NSTextView *)editorView { - int i; + unsigned i; - for (i = 0; i < 2 && highlited_chars[i] != -1; i++) {}; - -// if (isCharacterHighlit == NO) - if (i < 2) + for (i = 0; i < 2; i++) { + if (highlited_chars[i] == NSNotFound) + return; + NSTextStorage *textStorage = [editorView textStorage]; - NSRange r = NSMakeRange(location, 1); + NSRange r = NSMakeRange(highlited_chars[i], 1); NSRange tmp; -// NSLog(@"highlight"); - -// 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 + atIndex:r.location effectiveRange:&tmp]); ASSIGN(previousBGColor, [textStorage attribute:NSBackgroundColorAttributeName - atIndex:location + atIndex:r.location effectiveRange:&tmp]); ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName - atIndex:location + atIndex:r.location effectiveRange:&tmp]); [textStorage addAttribute:NSFontAttributeName @@ -1478,7 +1480,7 @@ NSUInteger FindDelimiterInString(NSString * string, selectedRange = [editorView selectedRange]; // make sure we un-highlight a previously highlit delimiter - [self unhighlightCharacter :editorView]; + // [self unhighlightCharacter :editorView]; // if we have a character at the selected location, check // to see if it is a delimiter character @@ -1508,8 +1510,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]; + highlited_chars[0] = selectedRange.location; + highlited_chars[1] = result; + [self highlightCharacterPair :editorView]; } } } From d6a2ce3650c2ed913c405e883caf45b6c8ca7389 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Thu, 28 Oct 2021 01:36:39 +0200 Subject: [PATCH 2/8] remove foreground color, we do not change it when highlighting --- Modules/Editors/ProjectCenter/PCEditor.h | 3 +-- Modules/Editors/ProjectCenter/PCEditor.m | 23 ----------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 01799de..4e30242 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -81,7 +81,6 @@ // 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; @@ -147,7 +146,7 @@ @interface PCEditor (Parenthesis) - (void)unhighlightCharacter: (NSTextView *)editorView; -- (void)highlightCharacterAt:(NSUInteger)location inEditor: (NSTextView *)editorView; +- (void)highlightCharacterPair: (NSTextView *)editorView; - (void)computeNewParenthesisNesting: (NSTextView *)editorView; @end diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index d3e980b..87775d4 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -219,7 +219,6 @@ ASSIGN(backgroundColor, [NSColor whiteColor]); ASSIGN(readOnlyColor, [NSColor lightGrayColor]); - previousFGColor = nil; previousBGColor = nil; previousFont = nil; @@ -1390,18 +1389,6 @@ NSUInteger FindDelimiterInString(NSString * string, [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 @@ -1437,10 +1424,6 @@ NSUInteger FindDelimiterInString(NSString * string, [textStorage beginEditing]; // store the previous character's attributes - ASSIGN(previousFGColor, - [textStorage attribute:NSForegroundColorAttributeName - atIndex:r.location - effectiveRange:&tmp]); ASSIGN(previousBGColor, [textStorage attribute:NSBackgroundColorAttributeName atIndex:r.location @@ -1455,12 +1438,6 @@ NSUInteger FindDelimiterInString(NSString * string, [textStorage addAttribute:NSBackgroundColorAttributeName value:highlightColor range:r]; -/* [textStorage addAttribute:NSForegroundColorAttributeName - value:highlightColor - range:r]; - - [textStorage removeAttribute:NSBackgroundColorAttributeName - range:r];*/ [textStorage endEditing]; } From 8ab1b66eb5b043cb3b58b757d0537bfe1ad49395 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Thu, 28 Oct 2021 01:40:01 +0200 Subject: [PATCH 3/8] fix spelling error in ivar --- Modules/Editors/ProjectCenter/PCEditor.h | 2 +- Modules/Editors/ProjectCenter/PCEditor.m | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 4e30242..f9b0531 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -77,7 +77,7 @@ // location of the highlighted delimiter characters // NSNotFound means not set - NSUInteger highlited_chars[2]; + NSUInteger highlighted_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 diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 87775d4..a16dd50 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -222,8 +222,8 @@ previousBGColor = nil; previousFont = nil; - highlited_chars[0] = NSNotFound; - highlited_chars[1] = NSNotFound; + highlighted_chars[0] = NSNotFound; + highlighted_chars[1] = NSNotFound; undoManager = [[NSUndoManager alloc] init]; } @@ -1372,10 +1372,10 @@ NSUInteger FindDelimiterInString(NSString * string, for (i = 0; i < 2; i++) { - if (highlited_chars[i] == NSNotFound) + if (highlighted_chars[i] == NSNotFound) continue; - NSRange r = NSMakeRange(highlited_chars[i], 1); + NSRange r = NSMakeRange(highlighted_chars[i], 1); // restore the character's color and font attributes if (previousFont != nil) @@ -1401,7 +1401,7 @@ NSUInteger FindDelimiterInString(NSString * string, range:r]; } - highlited_chars[i] = NSNotFound; + highlighted_chars[i] = NSNotFound; } [textStorage endEditing]; @@ -1413,11 +1413,11 @@ NSUInteger FindDelimiterInString(NSString * string, for (i = 0; i < 2; i++) { - if (highlited_chars[i] == NSNotFound) + if (highlighted_chars[i] == NSNotFound) return; NSTextStorage *textStorage = [editorView textStorage]; - NSRange r = NSMakeRange(highlited_chars[i], 1); + NSRange r = NSMakeRange(highlighted_chars[i], 1); NSRange tmp; NSAssert(textStorage, @"textstorage can't be nil"); @@ -1487,8 +1487,8 @@ NSUInteger FindDelimiterInString(NSString * string, // and in case a delimiter is found, highlight it if (result != NSNotFound) { - highlited_chars[0] = selectedRange.location; - highlited_chars[1] = result; + highlighted_chars[0] = selectedRange.location; + highlighted_chars[1] = result; [self highlightCharacterPair :editorView]; } } From 1749847eac237714553cb938af0b0b53ce5c74e6 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 23 Nov 2021 00:42:13 +0100 Subject: [PATCH 4/8] minor optimizations --- Modules/Editors/ProjectCenter/PCEditor.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index a16dd50..1063721 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -1410,27 +1410,27 @@ NSUInteger FindDelimiterInString(NSString * string, - (void)highlightCharacterPair:(NSTextView *)editorView { unsigned i; + NSTextStorage *textStorage = [editorView textStorage]; + + [textStorage beginEditing]; for (i = 0; i < 2; i++) { if (highlighted_chars[i] == NSNotFound) - return; + continue; - NSTextStorage *textStorage = [editorView textStorage]; NSRange r = NSMakeRange(highlighted_chars[i], 1); - NSRange tmp; NSAssert(textStorage, @"textstorage can't be nil"); - [textStorage beginEditing]; // store the previous character's attributes ASSIGN(previousBGColor, [textStorage attribute:NSBackgroundColorAttributeName atIndex:r.location - effectiveRange:&tmp]); + effectiveRange:NULL]); ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName atIndex:r.location - effectiveRange:&tmp]); + effectiveRange:NULL]); [textStorage addAttribute:NSFontAttributeName value:highlightFont @@ -1439,8 +1439,8 @@ NSUInteger FindDelimiterInString(NSString * string, value:highlightColor range:r]; - [textStorage endEditing]; } + [textStorage endEditing]; } - (void)computeNewParenthesisNesting: (NSTextView *)editorView From a0856faf214924e432b74feeff86f2fec350c43f Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 23 Nov 2021 01:09:50 +0100 Subject: [PATCH 5/8] remane textBackground to textBackgroundColor and use that for restoring highlit characters, without resding/storing such attribute --- Modules/Editors/ProjectCenter/PCEditor.h | 6 ++--- Modules/Editors/ProjectCenter/PCEditor.m | 29 +++++++----------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index f9b0531..637283d 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -73,15 +73,15 @@ NSColor *highlightColor; NSColor *backgroundColor; NSColor *readOnlyColor; - NSColor *textBackground; + NSColor *textBackgroundColor; // location of the highlighted delimiter characters // NSNotFound means not set NSUInteger highlighted_chars[2]; - // the stored color and font attributes of the highlit character, so + // the stored font attributes of the highlit character, so // that they can be restored later on when the character is un-highlit - NSColor *previousBGColor; + // A pair is assumed to have the same attributes NSColor *previousFont; // This is used to protect that -textViewDidChangeSelection: invocations diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 1063721..55330e0 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -136,7 +136,7 @@ RELEASE(lm); ev = [[PCEditorView alloc] initWithFrame:fr textContainer:tc]; - [ev setBackgroundColor:textBackground]; + [ev setBackgroundColor:textBackgroundColor]; [ev setTextColor:textColor]; [ev setEditor:self]; if (_highlightSyntax) @@ -218,8 +218,7 @@ ASSIGN(textColor, [NSColor blackColor]); ASSIGN(backgroundColor, [NSColor whiteColor]); ASSIGN(readOnlyColor, [NSColor lightGrayColor]); - - previousBGColor = nil; + previousFont = nil; highlighted_chars[0] = NSNotFound; @@ -306,17 +305,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]; @@ -1389,17 +1388,9 @@ NSUInteger FindDelimiterInString(NSString * string, [textStorage removeAttribute:NSFontAttributeName range:r]; } - if (previousBGColor != nil) - { - [textStorage addAttribute:NSBackgroundColorAttributeName - value:previousBGColor - range:r]; - } - else - { - [textStorage removeAttribute:NSBackgroundColorAttributeName - range:r]; - } + [textStorage addAttribute:NSBackgroundColorAttributeName + value:textBackgroundColor + range:r]; highlighted_chars[i] = NSNotFound; } @@ -1424,10 +1415,6 @@ NSUInteger FindDelimiterInString(NSString * string, NSAssert(textStorage, @"textstorage can't be nil"); // store the previous character's attributes - ASSIGN(previousBGColor, - [textStorage attribute:NSBackgroundColorAttributeName - atIndex:r.location - effectiveRange:NULL]); ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName atIndex:r.location effectiveRange:NULL]); From 01a3a61b2e6613335557233a5ddd886f699aa692 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 23 Nov 2021 01:22:54 +0100 Subject: [PATCH 6/8] do not change font on highlight, just the background: thus storing the old font attributes becomes needless --- Modules/Editors/ProjectCenter/PCEditor.h | 5 ----- Modules/Editors/ProjectCenter/PCEditor.m | 22 ---------------------- 2 files changed, 27 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 637283d..1917a8e 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -78,11 +78,6 @@ // location of the highlighted delimiter characters // NSNotFound means not set NSUInteger highlighted_chars[2]; - - // the stored font attributes of the highlit character, so - // that they can be restored later on when the character is un-highlit - // A pair is assumed to have the same attributes - NSColor *previousFont; // This is used to protect that -textViewDidChangeSelection: invocations // don't do anything when the text view changing, because this causes diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 55330e0..c5b4213 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -219,8 +219,6 @@ ASSIGN(backgroundColor, [NSColor whiteColor]); ASSIGN(readOnlyColor, [NSColor lightGrayColor]); - previousFont = nil; - highlighted_chars[0] = NSNotFound; highlighted_chars[1] = NSNotFound; @@ -1376,18 +1374,6 @@ NSUInteger FindDelimiterInString(NSString * string, NSRange r = NSMakeRange(highlighted_chars[i], 1); - // restore the character's color and font attributes - if (previousFont != nil) - { - [textStorage addAttribute:NSFontAttributeName - value:previousFont - range:r]; - } - else - { - [textStorage removeAttribute:NSFontAttributeName range:r]; - } - [textStorage addAttribute:NSBackgroundColorAttributeName value:textBackgroundColor range:r]; @@ -1414,14 +1400,6 @@ NSUInteger FindDelimiterInString(NSString * string, NSAssert(textStorage, @"textstorage can't be nil"); - // store the previous character's attributes - ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName - atIndex:r.location - effectiveRange:NULL]); - - [textStorage addAttribute:NSFontAttributeName - value:highlightFont - range:r]; [textStorage addAttribute:NSBackgroundColorAttributeName value:highlightColor range:r]; From 4216c13cda09f0c424efe140f00bcb1d90ed71ef Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Fri, 26 Nov 2021 02:20:40 +0100 Subject: [PATCH 7/8] 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. --- ChangeLog | 7 ++++++ Modules/Editors/ProjectCenter/PCEditor.h | 3 +++ Modules/Editors/ProjectCenter/PCEditor.m | 28 ++++++++++++++++-------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f24604..5e20616 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-11-26 Riccardo Mottola + + * 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-08-18 Riccardo Mottola * Modules/Editors/ProjectCenter/PCEditor.m diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 1917a8e..5e24d64 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -85,6 +85,9 @@ // of this method. BOOL editorTextViewIsPressingKey; + // Slightly delay drawing of highlit parentheses + NSTimer *phlTimer; + // keep one undo manager for the editor NSUndoManager *undoManager; } diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index c5b4213..ed6a5c3 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -962,12 +962,6 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange object = [notification object]; - if (editorTextViewIsPressingKey == NO) - { - if (object == _intEditorView || object == _extEditorView) - [self computeNewParenthesisNesting: object]; - } - NSLog(@"textViewDidChangeSelection"); // calculate current line if ([object isKindOfClass:[NSTextView class]]) @@ -1009,7 +1003,6 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange - (void)editorTextViewWillPressKey:sender { editorTextViewIsPressingKey = YES; -// NSLog(@"Will pressing key"); if (sender == _intEditorView || sender == _extEditorView) [self unhighlightCharacter: sender]; @@ -1019,9 +1012,20 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange - (void)editorTextViewDidPressKey:sender { -// NSLog(@"Did pressing key"); 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"); @@ -1408,6 +1412,12 @@ NSUInteger FindDelimiterInString(NSString * string, [textStorage endEditing]; } +- (void)computeNewParenthesisNestingFromTimer:(NSTimer *)timer +{ + phlTimer = nil; + [self computeNewParenthesisNesting:[timer userInfo]]; +} + - (void)computeNewParenthesisNesting: (NSTextView *)editorView { NSRange selectedRange; From c0f24a756f06d8868b8c59d6d272615ccac31a7e Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Sun, 28 Nov 2021 23:40:43 +0100 Subject: [PATCH 8/8] cleanup some debug logs --- Modules/Editors/ProjectCenter/PCEditor.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index ed6a5c3..aa8769f 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -943,9 +943,8 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange { - NSLog(@"Will change selection from %@ to %@", NSStringFromRange(oldSelectedCharRange), NSStringFromRange(newSelectedCharRange)); + NSDebugLog(@"Will change selection from %@ to %@", NSStringFromRange(oldSelectedCharRange), NSStringFromRange(newSelectedCharRange)); - NSLog(@"is pressing key %d", editorTextViewIsPressingKey); if (editorTextViewIsPressingKey == NO) { // unhighlight also invalidates old locations @@ -962,7 +961,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange object = [notification object]; - NSLog(@"textViewDidChangeSelection"); + NSDebugLog(@"received textViewDidChangeSelection notification"); // calculate current line if ([object isKindOfClass:[NSTextView class]]) { @@ -996,7 +995,7 @@ willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange selLine = nlCount + 1; } - NSLog(@"%u corresponds to %u", selection.location, selLine); + NSLog(@"%u corresponds to %u", (unsigned int)selection.location, (unsigned int)selLine); } } @@ -1431,8 +1430,9 @@ NSUInteger FindDelimiterInString(NSString * string, NSAssert(editorView, @"computeNewParenthesis: editorView is nil"); selectedRange = [editorView selectedRange]; - // make sure we un-highlight a previously highlit delimiter - // [self unhighlightCharacter :editorView]; + // 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 // to see if it is a delimiter character