setText:
などの変更は、Text Storage のNSTextStorageDidProcessEditingNotification
によって、undoManager
のgroupingLevel
が0
の時だけremoveAllActions
を呼ぶ。groupingLevel
はキーボードから入力があった時は RunLoop が終わらないと0
にならない。- キーボードから入力したときには、
coalesceInTextView:affectedRange:replacementRange:replacementText:
で、 まず最初にundoManager
に Text Storage をtarget
、_UITextUndoOperationTyping
をobject
にした Undo が登録される。 - 次回の入力以降、
coalesceInTextView:affectedRange:replacementRange:replacementText:
では、NSUndoManager
の_shouldCoalesceTypingForText::
(これは::
二回で正しい、2つめの引数は名前がない。) を呼んで、 前回の_UITextUndoOperationTyping
に変更を追記する方法で入力の Undo を結合するか、新しい Undo を登録するか決めている。 改行の直後などでは新しい Undo が追加される。 - この挙動があるため、
setText:
をキーボード入力があった RunLoop の途中で呼ぶと、removeAllActions
が呼ばれず、 その結果 Text Storage の内容が変わると、_UITextUndoOperationTyping
の内容と齟齬が発生して、場合によってはクラッシュする。
Last active
June 21, 2020 15:02
-
-
Save niw/b8f2eaa957924b8ea4d29034d7544434 to your computer and use it in GitHub Desktop.
Text View の内容を変更したりすると Undo でクラッシュしたりする原因はこれ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment