Closed dujj closed 3 years ago
数字键盘比较容易复现: 字母键盘,适合三指滑动撤销崩溃:
https://user-images.githubusercontent.com/9443889/102967233-72183a00-452c-11eb-9aa2-e92eb4b1c9fd.MP4
- 编辑框,设置最大长度
- 切换到系统中文输入法
- 输入字符到达最大长度后,删掉一个字符,再输入一串拼音(也即产生 markedTextRange)
- 三指滑动撤销,crash
以 QMUITextView 为例,在第4步触发系统的 undo 时,会直接调用 UITextViewTextDidChangeNotification
,此时系统的 undoManager 已经记录了当下的文本框操作历史,但由于 QMUITextView 在 handleTextChanged:
里有最长字符限制,需要去修改当前的 text,所以导致系统记录完文本操作历史后又产生了新的、不被记录的文本变化,于是最终执行 undo 时数据前后不匹配,crash。
新版本会修复该问题,在此之前可以先将以下代码添加到 -[QMUITextView handleTextChanged:]
方法内临时修复:
if (textView.maximumTextLength < NSUIntegerMax && textView.undoManager.undoing) {
return;
}
对于 QMUITextField 临时修复代码相同:
if (textField.maximumTextLength < NSUIntegerMax && textField.undoManager.undoing) {
return;
}
https://user-images.githubusercontent.com/9443889/102985941-f37ec500-454a-11eb-9af0-8091eda52ec3.MP4
上述修改方案,数字键盘,按新步骤,还是crash
只要有最大长度设置的,数字键盘的编辑框,不管什么app,几乎都会崩溃,已经测试过微信,斗鱼,都crash
上述修改方案,数字键盘,按新步骤,还是crash
无法重现
Bug 表现 系统三指撤销, crash 经测试,在微信,斗鱼,等多个应用也会出现此问题
如何重现
预期的表现 不会crash
修复方案: 1、完全屏蔽cut,past,copy方法,似乎不会响应三指撤销 2、以下代码,也可解决,但未充分测试: @implementation _QMUITextFieldDelegator
pragma mark -
(BOOL)textField:(QMUITextField )textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString )string { if (textField.maximumTextLength < NSUIntegerMax) {
其他信息