我正在尝试将撤消/重做功能集成到 UITextView (我正在构建 LateX 编辑器)中,但没有成功,说实话我对这个论点真的很困惑。我不明白这两个操作涉及的步骤,我的意思是我需要两种方法,
- 一种是删除最后插入的文本,
- 一种是恢复删除的文本,
一个疑问是我在哪里获取最后插入的文本?换句话说,我必须在哪里注册撤消?
- 在textViewDidChange中我可以在textViewShouldChangeTextInRange中获取整个文本
- 我可以插入最后一个字符
我知道我写的并不是最好的解释,但我希望这里有人过去遇到过同样的问题并且可以给我一个提示。基本上,要恢复,我必须将撤消/重做功能添加到文本视图,可能有两个与这些操作链接的按钮。
提前致谢
I'm trying to integrate the undo/redo features in a UITextView (I'm building a LateX editor) with no luck and to be honest I'm really confused about this argument. I don't understand the steps involved in those two operations, I mean I need two methods
- one to remove the last inserted text
- one to restore the text removed
One doubt is where I get the last inserted text? in other words where I have to register for the undo?
- in textViewDidChange I can get the whole text
- in textViewShouldChangeTextInRange I can get the last char inserted
I know that what I wrote wasn't the best explanation ever, But I hope someone here has faced the same problem in the past and can give me an hint. Basically ,to resume, I have to add the undo/redo features to a textview, possibly having two buttons linked with those actions.
Thanks in advance
发布评论
评论(1)
我现在感觉像个白痴:(解决方案真的很简单...textView已经有一个undoManager,所以基本上对textView进行撤消/重做操作的步骤是:
inside viewDidload :
你想要执行操作的地方
有时我真的很愚蠢,我几乎在编写自己的撤消代码......我希望这可以帮助别人
I'm feeling like an idiot right now :( the solution was really really easy... The textView has already an undoManager so basically the steps to have undo/redo actions for a textView are :
inside viewDidload :
where you want to perform the actions
I'm really dumb sometimes, I was almost writing my own undo code... I hope this can help someone