修改键盘长按立即清空和撤销删除

This commit is contained in:
2025-12-26 11:47:44 +08:00
parent 8e934dd83a
commit 203f104ece
28 changed files with 798 additions and 71 deletions

View File

@@ -20,6 +20,7 @@
#import "KBKeyboardSubscriptionView.h"
#import "KBKeyboardSubscriptionProduct.h"
#import "KBBackspaceUndoManager.h"
#import "KBInputBufferManager.h"
#import "KBSuggestionEngine.h"
// 使 static kb_consumePendingShopSkin
@@ -93,6 +94,14 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[KBLocalizationManager shared] reloadFromSharedStorageIfNeeded];
[[KBInputBufferManager shared] seedIfEmptyWithContextBefore:self.textDocumentProxy.documentContextBeforeInput
after:self.textDocumentProxy.documentContextAfterInput];
}
- (void)textDidChange:(id<UITextInput>)textInput {
[super textDidChange:textInput];
[[KBInputBufferManager shared] updateFromExternalContextBefore:self.textDocumentProxy.documentContextBeforeInput
after:self.textDocumentProxy.documentContextAfterInput];
}
@@ -369,22 +378,27 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
NSString *text = key.output ?: key.title ?: @"";
[self.textDocumentProxy insertText:text];
[self kb_updateCurrentWordWithInsertedText:text];
[[KBInputBufferManager shared] appendText:text];
} break;
case KBKeyTypeBackspace:
[[KBBackspaceUndoManager shared] recordDeletionSnapshotBefore:self.textDocumentProxy.documentContextBeforeInput
after:self.textDocumentProxy.documentContextAfterInput];
[self.textDocumentProxy deleteBackward];
[[KBInputBufferManager shared] refreshFromProxyIfPossible:self.textDocumentProxy];
[[KBInputBufferManager shared] prepareSnapshotForDeleteWithContextBefore:self.textDocumentProxy.documentContextBeforeInput
after:self.textDocumentProxy.documentContextAfterInput];
[[KBBackspaceUndoManager shared] captureAndDeleteBackwardFromProxy:self.textDocumentProxy count:1];
[self kb_scheduleContextRefreshResetSuppression:NO];
[[KBInputBufferManager shared] applyHoldDeleteCount:1];
break;
case KBKeyTypeSpace:
[[KBBackspaceUndoManager shared] registerNonClearAction];
[self.textDocumentProxy insertText:@" "];
[self kb_clearCurrentWord];
[[KBInputBufferManager shared] appendText:@" "];
break;
case KBKeyTypeReturn:
[[KBBackspaceUndoManager shared] registerNonClearAction];
[self.textDocumentProxy insertText:@"\n"];
[self kb_clearCurrentWord];
[[KBInputBufferManager shared] appendText:@"\n"];
break;
case KBKeyTypeGlobe:
[self advanceToNextInputMode]; break;
@@ -419,6 +433,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
[[KBBackspaceUndoManager shared] registerNonClearAction];
[self.textDocumentProxy insertText:emoji];
[self kb_clearCurrentWord];
[[KBInputBufferManager shared] appendText:emoji];
}
- (void)keyBoardMainViewDidTapUndo:(KBKeyBoardMainView *)keyBoardMainView {
@@ -432,6 +447,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
- (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didSelectSuggestion:(NSString *)suggestion {
if (suggestion.length == 0) { return; }
[[KBBackspaceUndoManager shared] registerNonClearAction];
NSString *current = self.currentWord ?: @"";
if (current.length > 0) {
for (NSUInteger i = 0; i < current.length; i++) {
@@ -443,6 +459,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
[self.suggestionEngine recordSelection:suggestion];
self.suppressSuggestions = YES;
[self.keyBoardMainView kb_setSuggestions:@[]];
[[KBInputBufferManager shared] replaceTailWithText:suggestion deleteCount:current.length];
}
// MARK: - KBFunctionViewDelegate