Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Feb 14, 2024
1 parent 3309c0b commit 9777699
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 87 deletions.
10 changes: 5 additions & 5 deletions SquirrelApplicationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ typedef enum {
// Note: the SquirrelApplicationDelegate is instantiated automatically as an outlet of NSApp's instance
@interface SquirrelApplicationDelegate : NSObject <NSApplicationDelegate>

@property(nonatomic, copy) IBOutlet NSMenu *menu;
@property(nonatomic, strong) IBOutlet SquirrelPanel *panel;
@property(nonatomic, strong) IBOutlet id updater;
@property(nonatomic, weak) IBOutlet NSMenu *menu;
@property(nonatomic, weak) IBOutlet SquirrelPanel *panel;
@property(nonatomic, weak) IBOutlet id updater;

@property(nonatomic, readonly, strong) SquirrelConfig *config;
@property(nonatomic, strong, readonly) SquirrelConfig *config;
@property(nonatomic, readonly) SquirrelNotificationPolicy showNotifications;

- (IBAction)deploy:(id)sender;
Expand All @@ -39,7 +39,7 @@ typedef enum {

@interface NSApplication (SquirrelApp)

@property(nonatomic, readonly, strong) SquirrelApplicationDelegate *squirrelAppDelegate;
@property(nonatomic, strong, readonly) SquirrelApplicationDelegate *squirrelAppDelegate;

@end

Expand Down
2 changes: 1 addition & 1 deletion SquirrelInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef NS_ENUM(NSUInteger, SquirrelIndex) {

@interface SquirrelInputController : IMKInputController

@property(nonatomic, class, readonly) SquirrelInputController *currentController;
@property(class, strong, readonly) SquirrelInputController *currentController;

- (void)moveCursor:(NSUInteger)cursorPosition
toPosition:(NSUInteger)targetPosition
Expand Down
82 changes: 36 additions & 46 deletions SquirrelInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
#import <IOKit/hid/IOHIDLib.h>
#import <IOKit/hidsystem/IOHIDLib.h>

@interface SquirrelInputController (Private)
- (void)createSession;
- (void)destroySession;
- (void)rimeConsumeCommittedText;
- (void)rimeUpdate;
- (void)updateAppOptions;
@end

const int N_KEY_ROLL_OVER = 50;
static NSString *kFullWidthSpace = @" ";

Expand Down Expand Up @@ -727,11 +719,7 @@ - (void)showPanelWithPreedit:(NSString *)preedit
lastPage:lastPage];
}

@end // SquirrelController


// implementation of private interface
@implementation SquirrelInputController (Private)
#pragma mark - Private methods

- (void)createSession {
NSString *app = [self.client bundleIdentifier];
Expand Down Expand Up @@ -851,42 +839,44 @@ - (void)rimeUpdate {
NSUInteger length = UTF8LengthToUTF16Length(preedit, ctx.composition.length);
NSUInteger numCandidate = (NSUInteger)ctx.menu.num_candidates;

if (!_showingSwitcherMenu && !showingStatus) {
if (_inlineCandidate) {
const char *candidatePreview = ctx.commit_text_preview;
NSString *candidatePreviewText = candidatePreview ? @(candidatePreview) : @"";
if (_inlinePreedit) {
if (end <= caretPos && caretPos < length) {
candidatePreviewText = [candidatePreviewText stringByAppendingString:
[preeditText substringWithRange:NSMakeRange(caretPos, length - caretPos)]];
}
[self showPreeditString:candidatePreviewText
selRange:NSMakeRange(start, candidatePreviewText.length - (length - end) - start)
caretPos:caretPos < end ? caretPos : candidatePreviewText.length - (length - caretPos)];
} else {
if (end < caretPos && caretPos <= length) {
candidatePreviewText = [candidatePreviewText substringToIndex:candidatePreviewText.length - (caretPos - end)];
} else if (caretPos < end && end < length) {
candidatePreviewText = [candidatePreviewText substringToIndex:candidatePreviewText.length - (length - end)];
}
[self showPreeditString:candidatePreviewText
selRange:NSMakeRange(start - (caretPos < end),
candidatePreviewText.length - start + (caretPos < end))
caretPos:caretPos < end ? caretPos - 1 : candidatePreviewText.length];
if (_showingSwitcherMenu || showingStatus) {
_preeditString = nil;
_composedString = nil;
_originalString = nil;
} else if (_inlineCandidate) {
const char *candidatePreview = ctx.commit_text_preview;
NSString *candidatePreviewText = candidatePreview ? @(candidatePreview) : @"";
if (_inlinePreedit) {
if (end <= caretPos && caretPos < length) {
candidatePreviewText = [candidatePreviewText stringByAppendingString:
[preeditText substringWithRange:NSMakeRange(caretPos, length - caretPos)]];
}
[self showPreeditString:candidatePreviewText
selRange:NSMakeRange(start, candidatePreviewText.length - (length - end) - start)
caretPos:caretPos < end ? caretPos : candidatePreviewText.length - (length - caretPos)];
} else {
if (_inlinePreedit) {
[self showPreeditString:preeditText
selRange:NSMakeRange(start, end - start)
caretPos:caretPos];
} else {
// TRICKY: display a non-empty string to prevent iTerm2 from echoing each character in preedit.
// note this is a full-width space U+3000; using narrow characters like "..." will result in
// an unstable baseline when composing Chinese characters.
[self showPreeditString:preedit ? kFullWidthSpace : @""
selRange:NSMakeRange(0, 0)
caretPos:0];
if (end < caretPos && caretPos <= length) {
candidatePreviewText = [candidatePreviewText substringToIndex:candidatePreviewText.length - (caretPos - end)];
} else if (caretPos < end && end < length) {
candidatePreviewText = [candidatePreviewText substringToIndex:candidatePreviewText.length - (length - end)];
}
[self showPreeditString:candidatePreviewText
selRange:NSMakeRange(start - (caretPos < end),
candidatePreviewText.length - start + (caretPos < end))
caretPos:caretPos < end ? caretPos - 1 : candidatePreviewText.length];
}
} else {
if (_inlinePreedit) {
[self showPreeditString:preeditText
selRange:NSMakeRange(start, end - start)
caretPos:caretPos];
} else {
// TRICKY: display a non-empty string to prevent iTerm2 from echoing each character in preedit.
// note this is a full-width space U+3000; using narrow characters like "..." will result in
// an unstable baseline when composing Chinese characters.
[self showPreeditString:preedit ? kFullWidthSpace : @""
selRange:NSMakeRange(0, 0)
caretPos:0];
}
}
// update candidates
Expand Down
2 changes: 1 addition & 1 deletion SquirrelPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef enum {
// Store switch options that change style (color theme) settings
@property(nonatomic, strong) SquirrelOptionSwitcher *optionSwitcher;
// Status message before pop-up is displayed; nil before normal panel is displayed
@property(nonatomic, readonly, strong) NSString *statusMessage;
@property(nonatomic, strong, readonly) NSString *statusMessage;
// position of the text input I-beam cursor on screen.
@property(nonatomic, assign) NSRect IbeamRect;

Expand Down
51 changes: 17 additions & 34 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,7 @@ - (void)setAnnotationHeight:(CGFloat)height {
#pragma mark - Typesetting extensions for TextKit 1 (Mac OSX 10.9 to MacOS 11)

@interface SquirrelLayoutManager : NSLayoutManager <NSLayoutManagerDelegate>
@end

@implementation SquirrelLayoutManager
@end @implementation SquirrelLayoutManager

- (void)drawGlyphsForGlyphRange:(NSRange)glyphRange
atPoint:(NSPoint)origin {
Expand Down Expand Up @@ -919,9 +917,7 @@ - (NSRect) layoutManager:(NSLayoutManager *)layoutManager

API_AVAILABLE(macos(12.0))
@interface SquirrelTextLayoutFragment : NSTextLayoutFragment
@end

@implementation SquirrelTextLayoutFragment
@end @implementation SquirrelTextLayoutFragment

- (void)drawAtPoint:(CGPoint)point
inContext:(CGContextRef)context {
Expand Down Expand Up @@ -954,9 +950,7 @@ - (void)drawAtPoint:(CGPoint)point

API_AVAILABLE(macos(12.0))
@interface SquirrelTextLayoutManager : NSTextLayoutManager <NSTextLayoutManagerDelegate>
@end

@implementation SquirrelTextLayoutManager
@end @implementation SquirrelTextLayoutManager

- (BOOL) textLayoutManager:(NSTextLayoutManager *)textLayoutManager
shouldBreakLineBeforeLocation:(id<NSTextLocation>)location
Expand All @@ -983,25 +977,25 @@ - (NSTextLayoutFragment *)textLayoutManager:(NSTextLayoutManager *)textLayoutMan

@interface SquirrelView : NSView

@property(nonatomic, readonly) NSTextView *textView;
@property(nonatomic, readonly) NSTextStorage *textStorage;
@property(nonatomic, readonly, strong) SquirrelTheme *currentTheme;
@property(nonatomic, readonly) CAShapeLayer *shape;
@property(nonatomic, readonly) NSRect contentRect;
@property(nonatomic, readonly) NSRect preeditBlock;
@property(nonatomic, readonly) NSRect candidateBlock;
@property(nonatomic, readonly) NSRect pagingBlock;
@property(nonatomic, readonly) SquirrelAppear appear;
@property(nonatomic, readonly) NSEdgeInsets alignmentRectInsets;
@property(nonatomic, readonly) NSArray<NSValue *> *candidateRanges;
@property(nonatomic, strong, readonly) NSTextView *textView;
@property(nonatomic, strong, readonly) NSTextStorage *textStorage;
@property(nonatomic, strong, readonly) SquirrelTheme *currentTheme;
@property(nonatomic, strong, readonly) CAShapeLayer *shape;
@property(nonatomic, strong, readonly) NSMutableArray<NSBezierPath *> *candidatePaths;
@property(nonatomic, strong, readonly) NSMutableArray<NSBezierPath *> *pagingPaths;
@property(nonatomic, strong, readonly) NSBezierPath *deleteBackPath;
@property(nonatomic, strong, readonly) NSArray<NSValue *> *candidateRanges;
@property(nonatomic, readonly) NSRange preeditRange;
@property(nonatomic, readonly) NSRange highlightedPreeditRange;
@property(nonatomic, readonly) NSRange pagingRange;
@property(nonatomic, readonly) NSUInteger highlightedIndex;
@property(nonatomic, readonly) SquirrelIndex functionButton;
@property(nonatomic, readonly) NSBezierPath *deleteBackPath;
@property(nonatomic, readonly) NSMutableArray<NSBezierPath *> *candidatePaths;
@property(nonatomic, readonly) NSMutableArray<NSBezierPath *> *pagingPaths;
@property(nonatomic, readonly) NSRect contentRect;
@property(nonatomic, readonly) NSRect preeditBlock;
@property(nonatomic, readonly) NSRect candidateBlock;
@property(nonatomic, readonly) NSRect pagingBlock;
@property(nonatomic, readonly) NSEdgeInsets alignmentRectInsets;
@property(nonatomic, readonly) SquirrelAppear appear;

- (NSTextRange *)getTextRangeFromCharRange:(NSRange)charRange API_AVAILABLE(macos(12.0));

Expand Down Expand Up @@ -1056,10 +1050,6 @@ - (SquirrelAppear)appear {
return defaultAppear;
}

- (BOOL)allowsVibrancy {
return YES;
}

- (SquirrelTheme *)selectTheme:(SquirrelAppear)appear {
return appear == darkAppear ? _darkTheme : _defaultTheme;
}
Expand Down Expand Up @@ -1807,13 +1797,6 @@ - (void)updateLayer {
[self addToolTipRect:pageDownRect owner:[_textStorage attribute:NSToolTipAttributeName
atIndex:NSMaxRange(pagingRange) - 1
effectiveRange:NULL] userData:nil];
NSRect pageNumRect = NSMakeRect(NSMinX(pageUpRect),
NSMinY(pageUpRect),
NSMinX(pageDownRect) - NSMaxX(pageUpRect),
NSHeight(pageDownRect));
[self addToolTipRect:pageNumRect owner:[_textStorage attribute:NSToolTipAttributeName
atIndex:pagingRange.location + 2
effectiveRange:NULL] userData:nil];
}

// Set layers
Expand Down

0 comments on commit 9777699

Please sign in to comment.