重构键盘长按删除
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user