From ae35ca4c102a0d4e42fb2e4430eda279773bfe9e Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 19 Oct 2021 00:17:03 +0200 Subject: [PATCH] Remove insertText and handle keys through appropriate methods (inserTab, cancelOperation)Remove insertText and handle keys through appropriate methods (inserTab, cancelOperation) --- ChangeLog | 6 ++ Modules/Editors/ProjectCenter/PCEditorView.h | 2 - Modules/Editors/ProjectCenter/PCEditorView.m | 105 ++++--------------- 3 files changed, 25 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f24604..2eec1af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-10-19 Riccardo Mottola + + * 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 * Modules/Editors/ProjectCenter/PCEditor.m diff --git a/Modules/Editors/ProjectCenter/PCEditorView.h b/Modules/Editors/ProjectCenter/PCEditorView.h index 78131a1..ac22c9d 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.h +++ b/Modules/Editors/ProjectCenter/PCEditorView.h @@ -52,8 +52,6 @@ - (void)createSyntaxHighlighterForFileType:(NSString *)fileType; -- (void)insertText:text; - - (NSRect)selectionRect; // ===== diff --git a/Modules/Editors/ProjectCenter/PCEditorView.m b/Modules/Editors/ProjectCenter/PCEditorView.m index 2c41b3e..1785dcf 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.m +++ b/Modules/Editors/ProjectCenter/PCEditorView.m @@ -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