iOS-UITextView + NSUndoManager

发布于 2024-10-19 04:33:32 字数 416 浏览 5 评论 0原文

我正在尝试将撤消/重做功能集成到 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-10-26 04:33:32

我现在感觉像个白痴:(解决方案真的很简单...textView已经有一个undoManager,所以基本上对textView进行撤消/重做操作的步骤是:
inside viewDidload :

myUndoManager = [textView undoManager];

你想要执行操作的地方

[myUndoManager undo]; // or redo

有时我真的很愚蠢,我几乎在编写自己的撤消代码......我希望这可以帮助别人

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 :

myUndoManager = [textView undoManager];

where you want to perform the actions

[myUndoManager undo]; // or redo

I'm really dumb sometimes, I was almost writing my own undo code... I hope this can help someone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文