@@ -829,6 +829,10 @@ - (void)drawRect:(NSRect)dirtyRect {
829
829
CGPathRef preeditPath = CGPathCreateMutable ();
830
830
SquirrelTheme* theme = self.currentTheme ;
831
831
832
+ NSPoint textFieldOrigin = dirtyRect.origin ;
833
+ textFieldOrigin.y += theme.edgeInset .height ;
834
+ textFieldOrigin.x += theme.edgeInset .width ;
835
+
832
836
// Draw preedit Rect
833
837
NSRect backgroundRect = dirtyRect;
834
838
NSRect containingRect = dirtyRect;
@@ -1026,9 +1030,13 @@ - (void)drawRect:(NSRect)dirtyRect {
1026
1030
}
1027
1031
[panelLayer addSublayer: layer];
1028
1032
}
1033
+ [_textView
1034
+ setTextContainerInset: NSMakeSize (textFieldOrigin.x, textFieldOrigin.y)];
1029
1035
}
1030
1036
1031
- - (BOOL )clickAtPoint : (NSPoint )_point index : (NSInteger *)_index {
1037
+ - (BOOL )clickAtPoint : (NSPoint )_point
1038
+ index : (NSInteger *)_index
1039
+ preeditIndex : (NSInteger *)_preeditIndex {
1032
1040
if (CGPathContainsPoint (_shape.path , nil , _point, NO )) {
1033
1041
NSPoint point =
1034
1042
NSMakePoint (_point.x - self.textView .textContainerInset .width ,
@@ -1047,11 +1055,20 @@ - (BOOL)clickAtPoint:(NSPoint)_point index:(NSInteger*)_index {
1047
1055
point = NSMakePoint (point.x - NSMinX (lineFragment.typographicBounds ),
1048
1056
point.y - NSMinY (lineFragment.typographicBounds ));
1049
1057
index += [lineFragment characterIndexForPoint: point];
1050
- for (NSUInteger i = 0 ; i < _candidateRanges.count ; i += 1 ) {
1051
- NSRange range = [_candidateRanges[i] rangeValue ];
1052
- if (index >= range.location && index < NSMaxRange (range)) {
1053
- *_index = i;
1054
- break ;
1058
+ if (index >= _preeditRange.location &&
1059
+ index < NSMaxRange (_preeditRange)) {
1060
+ if (_preeditIndex) {
1061
+ *_preeditIndex = index ;
1062
+ }
1063
+ } else {
1064
+ for (NSUInteger i = 0 ; i < _candidateRanges.count ; i += 1 ) {
1065
+ NSRange range = [_candidateRanges[i] rangeValue ];
1066
+ if (index >= range.location && index < NSMaxRange (range)) {
1067
+ if (_index) {
1068
+ *_index = i;
1069
+ }
1070
+ break ;
1071
+ }
1055
1072
}
1056
1073
}
1057
1074
break ;
@@ -1227,7 +1244,7 @@ - (void)sendEvent:(NSEvent*)event {
1227
1244
case NSEventTypeLeftMouseDown: {
1228
1245
NSPoint point = [self mousePosition ];
1229
1246
NSInteger index = -1 ;
1230
- if ([_view clickAtPoint: point index :&index ]) {
1247
+ if ([_view clickAtPoint: point index :&index preeditIndex: nil ]) {
1231
1248
if (index >= 0 && index < _candidates.count ) {
1232
1249
_index = index ;
1233
1250
}
@@ -1236,7 +1253,15 @@ - (void)sendEvent:(NSEvent*)event {
1236
1253
case NSEventTypeLeftMouseUp: {
1237
1254
NSPoint point = [self mousePosition ];
1238
1255
NSInteger index = -1 ;
1239
- if ([_view clickAtPoint: point index :&index ]) {
1256
+ NSInteger preeditIndex = -1 ;
1257
+ if ([_view clickAtPoint: point index :&index preeditIndex: &preeditIndex]) {
1258
+ if (preeditIndex >= 0 && preeditIndex < _preedit.length ) {
1259
+ if (preeditIndex < _caretPos) {
1260
+ [_inputController moveCaret: YES ];
1261
+ } else if (preeditIndex > _caretPos) {
1262
+ [_inputController moveCaret: NO ];
1263
+ }
1264
+ }
1240
1265
if (index >= 0 && index < _candidates.count && index == _index) {
1241
1266
[_inputController selectCandidate: index ];
1242
1267
}
@@ -1261,7 +1286,7 @@ - (void)sendEvent:(NSEvent*)event {
1261
1286
case NSEventTypeMouseMoved: {
1262
1287
NSPoint point = [self mousePosition ];
1263
1288
NSInteger index = -1 ;
1264
- if ([_view clickAtPoint: point index :&index ]) {
1289
+ if ([_view clickAtPoint: point index :&index preeditIndex: nil ]) {
1265
1290
if (index >= 0 && index < _candidates.count && _cursorIndex != index ) {
1266
1291
[self showPreedit: _preedit
1267
1292
selRange: _selRange
@@ -1459,12 +1484,9 @@ - (void)show {
1459
1484
[self .contentView setBoundsOrigin: NSMakePoint (0 , 0 )];
1460
1485
[_view.textView setBoundsOrigin: NSMakePoint (0 , 0 )];
1461
1486
}
1487
+ BOOL translucency = theme.translucency ;
1462
1488
[_view setFrame: self .contentView.bounds];
1463
1489
[_view.textView setFrame: self .contentView.bounds];
1464
- [_view.textView setTextContainerInset: NSMakeSize (theme.edgeInset.width,
1465
- theme.edgeInset.height)];
1466
-
1467
- BOOL translucency = theme.translucency ;
1468
1490
if (translucency) {
1469
1491
[_back setFrame: self .contentView.bounds];
1470
1492
_back.appearance = NSApp .effectiveAppearance ;
0 commit comments