本文介绍了撤销/重做实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给我一些想法如何实现撤销/重做功能 - 就像我们在文本编辑器。什么算法,我应该用什么,我可以读取。谢谢。

Give me some thoughts how to implement undo/redo functionality - like we have in text editors.What algorithms should I use and what I may read. thanks.

推荐答案

我知道撤销的

  • 保存状态:一类撤消的是,你实际上是保存历史状态。在这种情况下,什么情况是,在每一点上,你继续保存状态在内存的位置。当你想要做撤销,你只需换出的当前状态和交换中已经存在于内存中的状态。这就是它与历史完成在Adobe Photoshop或重新打开关闭的标签页在谷歌浏览器,例如。
  • SAVE STATE:One category of undo is where you actually save history states. In this case what happens is that at every point you keep on saving the state in some location of memory. When you want to do an undo, you just swap out the current state and swap in the state which was already there in the memory. This is how it is done with History in Adobe Photoshop or reopening closed tabs in Google Chrome, for example.

  • 生成状态:另一类是,而不是维护自己的国家在哪里,你只记得是什么行为是。当你需要撤消,你需要做的特别行动的逻辑相反。举个简单的例子,当你做一个控制 + B 中的一些文本编辑器,支持撤消的,它也被称为a 粗体的行动。现在,每个动作是它的逻辑逆转的映射。所以,当你做了控制 + 以Z ,它看起来从一个相反的动作表,发现撤消操作是控制 + B 了。即执行,你会得到你的previous状态。所以,在这里你的previous状态并没有存储在内存中,但是当你需要的时候产生的。
  • GENERATE STATE:The other category is where instead of maintaining the states themselves, you just remember what the actions were. when you need to undo, you need to do a logical reverse of that particular action. For a simple example, when you do a + in some text editor that supports undo's, it is remembered as a Bold action. Now with each action is a mapping of its logical reverses. So, when you do a +, it looks up from a inverse actions table and finds that the undo action is a + again. That is performed and you get your previous state. So, here your previous state was not stored in memory but generated when you needed it.

有关文本编辑器,生成国家这种方式是不是过于计算密集型的,但对于像Adobe公司的Photoshop程序,它可能是计算量太大或只是简单的不可能。例如 - 对于模糊的动作,你会指定去模糊的行动,但不能让你到原来的状态,因为数据已经丢失。因此,根据不同的情况 - 一个逻辑反转动作的可能性,它的可行性,你需要这两大类别之间进行选择,然后实现他们你想要的方式。 Ofcourse,就可以有一个混合策略,为你工作。

For text editors, generating the state this way is not too computation intensive but for programs like Adobe Photoshop, it might be too computationally intensive or just plain impossible. For example - for a Blur action, you will specify a de-Blur action, but that can never get you to the original state because the data is already lost. So, depending on the situation - possibility of a logical inverse action and the feasibility of it, you need to choose between these two broad categories, and then implement them the way you want. Ofcourse, it is possible to have a hybrid strategy that works for you.

此外,有时,就像在Gmail中,时间有限的撤销都是不可能的,因为动作(发送邮件)从未在第一时间完成。所以,你是不是撤销荷兰国际集团在那里,你只是不这样做的行动本身。

Also, sometimes, like in Gmail, a time limited undo is possible because the action (sending the mail) is never done in the first place. So, you are not "undo"ing there, you are just "not doing" the action itself.

这篇关于撤销/重做实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:13