From fd5de4f19793ea7ccbad62bb8883a6bb87966bed Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 4 Mar 2026 14:36:59 +0800 Subject: [PATCH] 1 --- .../Utils/KBBackspaceLongPressHandler.m | 34 +++++++++++++++++++ CustomKeyboard/View/KBKeyBoardMainView.m | 5 +-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CustomKeyboard/Utils/KBBackspaceLongPressHandler.m b/CustomKeyboard/Utils/KBBackspaceLongPressHandler.m index cf6b1ad..ec362df 100644 --- a/CustomKeyboard/Utils/KBBackspaceLongPressHandler.m +++ b/CustomKeyboard/Utils/KBBackspaceLongPressHandler.m @@ -392,6 +392,7 @@ typedef NS_ENUM(NSInteger, KBClearPhase) { [[KBInputBufferManager shared] clearPendingClearSnapshot]; [[KBInputBufferManager shared] commitLiveToManual]; } + [self kb_refreshSuggestionsAfterLongPressClear:shouldClear]; } #pragma mark - Clear Label @@ -499,6 +500,7 @@ typedef NS_ENUM(NSInteger, KBClearPhase) { #pragma mark - Clear - (void)kb_clearAllInput { + [self kb_clearCurrentWordIfPossible]; UIResponder *start = (UIResponder *)([self kb_hostView] ?: self.backspaceButton); UIInputViewController *ivc = KBFindInputViewController(start); if (ivc) { @@ -659,4 +661,36 @@ typedef NS_ENUM(NSInteger, KBClearPhase) { #endif } +- (void)kb_clearCurrentWordIfPossible { + UIResponder *start = (UIResponder *)([self kb_hostView] ?: self.backspaceButton); + UIInputViewController *ivc = KBFindInputViewController(start); + if (!ivc) { return; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + if ([ivc respondsToSelector:@selector(kb_clearCurrentWord)]) { + [ivc performSelector:@selector(kb_clearCurrentWord)]; + } +#pragma clang diagnostic pop +} + +- (void)kb_refreshSuggestionsAfterLongPressClear:(BOOL)shouldClear { + NSTimeInterval delay = shouldClear ? 0.06 : 0.0; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), + dispatch_get_main_queue(), ^{ + [self kb_scheduleContextRefreshResetSuppression:NO]; + }); +} + +- (void)kb_scheduleContextRefreshResetSuppression:(BOOL)resetSuppression { + UIResponder *start = (UIResponder *)([self kb_hostView] ?: self.backspaceButton); + UIInputViewController *ivc = KBFindInputViewController(start); + if (!ivc) { return; } + SEL sel = @selector(kb_scheduleContextRefreshResetSuppression:); + if (![ivc respondsToSelector:sel]) { return; } + void (*func)(id, SEL, BOOL) = (void *)[ivc methodForSelector:sel]; + if (func) { + func(ivc, sel, resetSuppression); + } +} + @end diff --git a/CustomKeyboard/View/KBKeyBoardMainView.m b/CustomKeyboard/View/KBKeyBoardMainView.m index 2ec4156..90b249f 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.m +++ b/CustomKeyboard/View/KBKeyBoardMainView.m @@ -293,10 +293,7 @@ - (BOOL)kb_shouldShowSuggestions { if (self.emojiPanelVisible) { return NO; } - if (![KBBackspaceUndoManager shared].hasUndo && self.suggestionBarHasItems) { - return YES; - } - return NO; + return self.suggestionBarHasItems; } - (void)kb_applySuggestionVisibility {