重构键盘长按删除

This commit is contained in:
2025-12-19 18:45:14 +08:00
parent d90e080981
commit 9544ad75ff
5 changed files with 514 additions and 442 deletions

View File

@@ -25,6 +25,7 @@
#import "KBTagItemModel.h"
#import <MJExtension/MJExtension.h>
#import "KBBizCode.h"
#import "KBBackspaceLongPressHandler.h"
@interface KBFunctionView () <KBFunctionBarViewDelegate, KBStreamOverlayViewDelegate, KBFunctionTagListViewDelegate>
// UI
@@ -59,6 +60,7 @@
// UL
@property (nonatomic, assign) NSUInteger kb_ulSeq; // UL
@property (nonatomic, assign) BOOL kb_ulHandledFlag; // App UL
@property (nonatomic, strong) KBBackspaceLongPressHandler *backspaceHandler;
@end
@implementation KBFunctionView
@@ -67,6 +69,7 @@
if (self = [super initWithFrame:frame]) {
// 使
[self kb_applyTheme];
self.backspaceHandler = [[KBBackspaceLongPressHandler alloc] initWithContainerView:self];
[self setupUI];
// [self reloadDemoData];
@@ -770,22 +773,9 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
[proxy deleteBackward];
}
- (void)onTapClear {
- (void)onTapClear {
NSLog(@"点击:清空");
// pasteView
UIInputViewController *ivc = KBFindInputViewController(self);
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
// documentContextBeforeInput 50
NSInteger guard = 0; //
while (guard < 10000) {
NSString *before = proxy.documentContextBeforeInput ?: @"";
NSInteger count = before.length;
if (count <= 0) { break; } //
for (NSInteger i = 0; i < count; i++) {
[proxy deleteBackward];
}
guard += count;
}
[self.backspaceHandler performClearAction];
}
- (void)onTapSend {
NSLog(@"点击:发送");
@@ -872,6 +862,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
[_deleteButtonInternal setImage:[UIImage imageNamed:@"kb_del_icon"] forState:UIControlStateNormal];
[_deleteButtonInternal addTarget:self action:@selector(onTapDelete) forControlEvents:UIControlEventTouchUpInside];
[self.backspaceHandler bindDeleteButton:_deleteButtonInternal];
}
return _deleteButtonInternal;
}