Merge branch 'master' into ImproveHighlighting

This commit is contained in:
Riccardo 2021-11-28 23:59:25 +01:00 committed by GitHub
commit 008b192d99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 88 deletions

View file

@ -5,6 +5,12 @@
Furthermore, use a timer so that in case of rapid re-computing Furthermore, use a timer so that in case of rapid re-computing
it gets invalidated before and only calculated at the last event. 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> 2021-08-18 Riccardo Mottola <rm@gnu.org>
* Modules/Editors/ProjectCenter/PCEditor.m * Modules/Editors/ProjectCenter/PCEditor.m

View file

@ -52,8 +52,6 @@
- (void)createSyntaxHighlighterForFileType:(NSString *)fileType; - (void)createSyntaxHighlighterForFileType:(NSString *)fileType;
- (void)insertText:text;
- (NSRect)selectionRect; - (NSRect)selectionRect;
// ===== // =====

View file

@ -60,7 +60,7 @@
* @return The ammount of spaces the last line containing text is offset * @return The ammount of spaces the last line containing text is offset
* from it's start. * from it's start.
*/ */
static int ComputeIndentingOffset(NSString * string, unsigned int start) static int ComputeIndentingOffset(NSString * string, NSUInteger start)
{ {
SEL sel = @selector(characterAtIndex:); SEL sel = @selector(characterAtIndex:);
unichar (* charAtIndex)(NSString *, SEL, unsigned int) = unichar (* charAtIndex)(NSString *, SEL, unsigned int) =
@ -498,96 +498,29 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
[highlighter setBoldItalicFont: [self editorBoldItalicFont]]; [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 // ignore ESC char
* 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;
if ([text characterAtIndex:0] == 27) - (void) insertNewline: (id)sender
{ {
NSLog(@"ESC key pressed. Ignoring it"); NSInteger location = [self selectedRange].location;
return; int offset = ComputeIndentingOffset([self string], location);
} char buf[offset+2];
if ([string isEqualToString:@"\n"]) buf[0] = '\n';
{ memset(&buf[1], ' ', offset);
/* if ([[NSUserDefaults standardUserDefaults] buf[offset+1] = '\0';
boolForKey:@"ReturnDoesAutoindent"])
{*/
int location = [self selectedRange].location;
int offset = ComputeIndentingOffset([self string], location);
char *buf;
buf = (char *) malloc((offset + 2) * sizeof(unichar)); // let's use UTF8 to be on the safe side
buf[0] = '\n'; [self insertText: [NSString stringWithCString: buf
memset(&buf[1], ' ', offset); encoding: NSUTF8StringEncoding]];
buf[offset+1] = '\0'; }
#ifdef WIN32 - (void) insertTab: (id)sender
[super insertText:[NSString stringWithCString: buf {
encoding: NSUTF8StringEncoding]]; [self performIndentation];
#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
}
} }
/* This extra change tracking is required in order to inform the document /* This extra change tracking is required in order to inform the document