Fix more indentation logic. Get rid of old code.

This commit is contained in:
Gregory John Casamento 2021-06-19 23:47:03 -04:00
parent e0458a60e9
commit f3bacb49c1

View file

@ -95,28 +95,6 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
} }
return firstCharOffset >= 0 ? firstCharOffset : 0; return firstCharOffset >= 0 ? firstCharOffset : 0;
/* if (firstCharOffset >= 0)
{
// if the indenting of the current line is lower than the indenting
// of the previous actual line, we return the lower indenting
if (startOffsetFromLineStart >= 0 &&
startOffsetFromLineStart < firstCharOffset)
{
return startOffsetFromLineStart;
}
// otherwise we return the actual indenting, so that any excess
// space is trimmed and the lines are aligned according the last
// indenting level
else
{
return firstCharOffset;
}
}
else
{
return 0;
}*/
} }
@interface PCEditorView (Private) @interface PCEditorView (Private)
@ -285,7 +263,6 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
NSMutableString *indentString; NSMutableString *indentString;
NSCharacterSet *wsCharSet = [NSCharacterSet whitespaceCharacterSet]; NSCharacterSet *wsCharSet = [NSCharacterSet whitespaceCharacterSet];
NSInteger i; NSInteger i;
// int point;
location = [self selectedRange].location; location = [self selectedRange].location;
@ -362,11 +339,13 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
- (void) refreshHighlighting - (void) refreshHighlighting
{ {
NSRange selectedRange = [self selectedRange];
NSString *str = [self string]; NSString *str = [self string];
NSRange wsRange = NSMakeRange(0, [str length]); NSRange wsRange = NSMakeRange(0, [str length]);
[[self textStorage] [[self textStorage]
replaceCharactersInRange: wsRange replaceCharactersInRange: wsRange
withString: str]; withString: str];
[self setSelectedRange: selectedRange];
} }
@end @end
@ -484,25 +463,6 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
return editor; return editor;
} }
- (void)awakeFromNib
{
/* NSData * data;
NSUserDefaults * df = [NSUserDefaults standardUserDefaults];
drawCrosshairs = [df boolForKey: @"DrawCrosshairs"];
if (drawCrosshairs)
{
if ((data = [df dataForKey: @"CrosshairColor"]) == nil ||
(crosshairColor = [NSUnarchiver unarchiveObjectWithData: data]) == nil)
{
crosshairColor = [NSColor lightGrayColor];
}
[crosshairColor retain];
}
guides = [NSMutableArray new];*/
}
- (void) _highlightWithBoundingRect: (NSRect)r - (void) _highlightWithBoundingRect: (NSRect)r
{ {
if (highlighter) if (highlighter)
@ -539,13 +499,14 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
- (void) insertText: text - (void) insertText: text
{ {
/* NOTE: On Windows we ensure to get a string in UTF-8 encoding. The problem /* 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 * is the highlighter doesn't use a consistent codification causing a
* problem on Windows platform. Anyway, the plugin for Gemas editor works * problem on Windows platform. Anyway, the plugin for Gemas editor works
* better and don't show this problem. * better and doesn't show this problem.
*/ */
if ([text isKindOfClass:[NSString class]]) if ([text isKindOfClass:[NSString class]])
{ {
NSString * string = text; NSString * string = text;
BOOL indentWhenTyping = [[[NSUserDefaults standardUserDefaults] objectForKey: @"IndentWhenTyping"] boolValue];
if ([text characterAtIndex:0] == 27) if ([text characterAtIndex:0] == 27)
{ {
@ -568,10 +529,10 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
buf[offset+1] = '\0'; buf[offset+1] = '\0';
#ifdef WIN32 #ifdef WIN32
[super insertText:[NSString stringWithCString: buf [super insertText: [NSString stringWithCString: buf
encoding: NSUTF8StringEncoding]]; encoding: NSUTF8StringEncoding]];
#else #else
[super insertText:[NSString stringWithCString:buf]]; [super insertText: [NSString stringWithCString:buf]];
#endif #endif
free(buf); free(buf);
} }
@ -584,7 +545,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
{ {
[self performIndentation]; [self performIndentation];
} }
else if ([string isEqualToString: @"{"]) else if ([string isEqualToString: @"{"] && indentWhenTyping)
{ {
int tabSize = [[[NSUserDefaults standardUserDefaults] objectForKey: @"IndentWidth"] intValue]; int tabSize = [[[NSUserDefaults standardUserDefaults] objectForKey: @"IndentWidth"] intValue];
// [self setTextColor: [NSColor whiteColor]]; // [self setTextColor: [NSColor whiteColor]];