@@ -29,6 +29,9 @@ @implementation SquirrelInputController {
2929 NSString *_schemaId;
3030 BOOL _inlinePreedit;
3131 BOOL _inlineCandidate;
32+ // app-specific bug fix
33+ BOOL _inlinePlaceholder;
34+ BOOL _panellessCommitFix;
3235 // for chord-typing
3336 int _chordKeyCodes[N_KEY_ROLL_OVER];
3437 int _chordModifiers[N_KEY_ROLL_OVER];
@@ -196,6 +199,13 @@ -(BOOL)processKey:(int)rime_keycode modifiers:(int)rime_modifiers
196199 rime_get_api ()->set_option (_session, " ascii_mode" , True);
197200 // NSLog(@"turned Chinese mode off in vim-like editor's command mode");
198201 }
202+
203+ if (_panellessCommitFix && (rime_keycode == XK_Delete ||
204+ (rime_keycode >= XK_Home && rime_keycode <= XK_KP_Delete) ||
205+ (rime_keycode >= XK_BackSpace && rime_keycode <= XK_Escape))) {
206+ [self showPlaceholder: @" " ];
207+ return NO ;
208+ }
199209 }
200210
201211 // Simulate key-ups for every interesting key-down for chord-typing.
@@ -418,6 +428,14 @@ -(void)commitString:(NSString*)string
418428 [NSApp .squirrelAppDelegate.panel hide ];
419429}
420430
431+ -(void )showPlaceholder : (NSString *)placeholder {
432+ NSDictionary * attrs = [self markForStyle: kTSMHiliteSelectedRawText atRange: NSMakeRange (0 , MAX (placeholder.length, 1UL ))];
433+ NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc ] initWithString: placeholder ? : @" █" attributes: attrs];
434+ [_currentClient setMarkedText: attrString
435+ selectionRange: NSMakeRange (attrString.length, 0 )
436+ replacementRange: NSMakeRange (NSNotFound , NSNotFound )];
437+ }
438+
421439-(void )showPreeditString : (NSString *)preedit
422440 selRange : (NSRange )range
423441 caretPos : (NSUInteger )pos
@@ -508,6 +526,8 @@ -(void)updateAppOptions
508526 NSLog (@" set app option: %@ = %d " , key, value);
509527 rime_get_api ()->set_option (_session, key.UTF8String , value);
510528 }
529+ _panellessCommitFix = appOptions[@" panelless_commit_fix" ].boolValue ;
530+ _inlinePlaceholder = appOptions[@" inline_placeholder" ].boolValue ;
511531 }
512532}
513533
@@ -526,7 +546,10 @@ -(void)rimeConsumeCommittedText
526546 RIME_STRUCT (RimeCommit, commit);
527547 if (rime_get_api ()->get_commit (_session, &commit)) {
528548 NSString *commitText = @(commit.text );
529- [self commitString: commitText];
549+ if (_panellessCommitFix && [_currentClient markedRange ].length == 0 ) {
550+ [self showPlaceholder: nil ];
551+ }
552+ [self commitString: commitText];
530553 rime_get_api ()->free_commit (&commit);
531554 }
532555}
@@ -571,7 +594,9 @@ -(void)rimeUpdate
571594 NSUInteger end = substr (preedit, ctx.composition .sel_end ).length ;
572595 NSUInteger caretPos = substr (preedit, ctx.composition .cursor_pos ).length ;
573596 NSRange selRange = NSMakeRange (start, end - start);
574- if (_inlineCandidate) {
597+ if (_panellessCommitFix && !preedit) {
598+ [self showPlaceholder: nil ];
599+ } else if (_inlineCandidate) {
575600 const char *candidatePreview = ctx.commit_text_preview ;
576601 NSString *candidatePreviewText = candidatePreview ? @(candidatePreview) : @" " ;
577602 if (_inlinePreedit) {
@@ -595,7 +620,8 @@ -(void)rimeUpdate
595620 // TRICKY: display a non-empty string to prevent iTerm2 from echoing each character in preedit.
596621 // note this is a full-shape space U+3000; using half shape characters like "..." will result in
597622 // an unstable baseline when composing Chinese characters.
598- [self showPreeditString: (preedit ? @" " : @" " ) selRange: empty caretPos: 0 ];
623+ preedit && _inlinePlaceholder ? [self showPlaceholder: @" " ]
624+ : [self showPreeditString: @" " selRange: empty caretPos: 0 ];
599625 }
600626 }
601627 // update candidates
0 commit comments