From 19b63ff2424f3f358da603e8712170ceaba145bc Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Tue, 8 Dec 2020 09:28:48 -0500 Subject: [PATCH] Add tabKeyAlwaysIndentsOutdents property --- .../project.xcworkspace/contents.xcworkspacedata | 7 +++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Library/macOSRichTextEditor/Source/RichTextEditor.h | 4 ++++ Library/macOSRichTextEditor/Source/RichTextEditor.m | 12 ++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Library/macOSRichTextEditor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Library/macOSRichTextEditor/Source/RichTextEditor.h b/Library/macOSRichTextEditor/Source/RichTextEditor.h index 72084bd..e7f1ea3 100755 --- a/Library/macOSRichTextEditor/Source/RichTextEditor.h +++ b/Library/macOSRichTextEditor/Source/RichTextEditor.h @@ -129,6 +129,10 @@ typedef NS_OPTIONS(NSUInteger, RichTextEditorShortcut) { /// Minimum font size. Defaults to 10.0f. @property CGFloat minFontSize; +/// true if tab should always indent and shift+tab should always outdent the current paragraph(s); +/// false to let the tab key be used as normal +@property BOOL tabKeyAlwaysIndentsOutdents; + /// Pasteboard type string used when copying text from this NSTextView. +(NSString*)pasteboardDataType; diff --git a/Library/macOSRichTextEditor/Source/RichTextEditor.m b/Library/macOSRichTextEditor/Source/RichTextEditor.m index 7c94569..afec1ea 100644 --- a/Library/macOSRichTextEditor/Source/RichTextEditor.m +++ b/Library/macOSRichTextEditor/Source/RichTextEditor.m @@ -184,6 +184,10 @@ typedef NS_ENUM(NSInteger, ParagraphIndentation) { if (self.delegate_interceptor.receiver && [self.delegate_interceptor.receiver respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementString:)]) { return [self.delegate_interceptor.receiver textView:textView shouldChangeTextInRange:affectedCharRange replacementString:replacementString]; } + if (self.tabKeyAlwaysIndentsOutdents && [replacementString isEqualToString:@"\t"] && affectedCharRange.length == 0) { + //[self userSelectedIncreaseIndent]; + //return NO; + } return YES; } @@ -1392,6 +1396,14 @@ typedef NS_ENUM(NSInteger, ParagraphIndentation) { (enabledShortcuts == RichTextEditorShortcutAll || enabledShortcuts & RichTextEditorShortcutIncreaseIndent)) { [self userSelectedIncreaseIndent]; } + else if (self.tabKeyAlwaysIndentsOutdents && keyChar == '\t' && !commandKeyDown && !shiftKeyDown && + (enabledShortcuts == RichTextEditorShortcutAll || enabledShortcuts & RichTextEditorShortcutIncreaseIndent)) { + [self userSelectedIncreaseIndent]; + } + else if (self.tabKeyAlwaysIndentsOutdents && (keyChar == '\t' || keyChar == 25) && !commandKeyDown && shiftKeyDown && + (enabledShortcuts == RichTextEditorShortcutAll || enabledShortcuts & RichTextEditorShortcutIncreaseIndent)) { + [self userSelectedDecreaseIndent]; + } else if (!([self.rteDelegate respondsToSelector:@selector(richTextEditor:keyDownEvent:)] && [self.rteDelegate richTextEditor:self keyDownEvent:event])) { [self sendDelegatePreviewChangeOfType:RichTextEditorPreviewChangeKeyDown]; [super keyDown:event];