Skip to content

Commit

Permalink
1.0-Alpha 6 - Now implemented expected behavor without sacificing cen…
Browse files Browse the repository at this point in the history
…ter alignment for answer text field
  • Loading branch information
丈槍由紀 committed Feb 12, 2022
1 parent 2cfadb8 commit 91324fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
3 changes: 1 addition & 2 deletions KaniManabu-macOS/Support/TKMKanaInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

#import <AppKit/AppKit.h>


@interface TKMKanaInputTextField : NSTextField <NSTextViewDelegate>
@property int StartLocation;
@property (strong)NSTextView *textvieweditor;
@end


NS_ASSUME_NONNULL_BEGIN

extern NSString *TKMConvertKanaText(NSString *text);
Expand Down
25 changes: 11 additions & 14 deletions KaniManabu-macOS/Support/TKMKanaInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void EnsureInitialised() {
}

@implementation TKMKanaInputTextField

- (void)keyUp:(NSEvent *)event {
if (event.keyCode == 123 || event.keyCode == 124) {
self.StartLocation = self.currentEditor.selectedRange.location;
Expand All @@ -383,28 +384,24 @@ - (BOOL)becomeFirstResponder

NSTextView * fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:self];
fieldEditor.delegate = self;
self.textvieweditor = fieldEditor;
NSClickGestureRecognizer *recognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(singleClickGesture:)];
[self.textvieweditor addGestureRecognizer:recognizer];
//[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(kanaTextViewClicked:) name:@"KanaEditorTextViewClicked" object:nil];
//NSClickGestureRecognizer *recognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(singleClickGesture:)];
//[self.textvieweditor addGestureRecognizer:recognizer];
return YES;
}

- (void)singleClickGesture:(NSClickGestureRecognizer *)recognizer {
NSLog(@"qq");
if (recognizer.state == NSGestureRecognizerStateEnded) {
[self.textvieweditor setEditable:YES];
if ([self.window makeFirstResponder:self.textvieweditor]) {
NSPoint location = [recognizer locationInView:self.textvieweditor];
NSUInteger position = [_textvieweditor characterIndexForInsertionAtPoint:location];
_textvieweditor.selectedRange = NSMakeRange(position, 0);
self.StartLocation = self.currentEditor.selectedRange.location;
}
- (void)textViewDidChangeSelection:(NSNotification *)notification {
NSEvent *event = NSApplication.sharedApplication.currentEvent;
if (event.type == NSEventTypeLeftMouseUp) {
//NSLog(@"Mouse clicked");
self.StartLocation = self.currentEditor.selectedRange.location;
//NSLog(@"New Location: %i",_StartLocation);
}
}


@end


@implementation TKMKanaInput

- (instancetype)init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<textField focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="V0c-Ys-uF1" customClass="TKMKanaInputTextField">
<rect key="frame" x="0.0" y="13" width="514" height="46"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" focusRingType="none" alignment="left" drawsBackground="YES" id="X2d-ZP-q78">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" focusRingType="none" alignment="center" drawsBackground="YES" id="X2d-ZP-q78">
<font key="font" metaFont="system" size="24"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down

0 comments on commit 91324fd

Please sign in to comment.