Skip to content

Improving the supporting of history #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

cauchywei
Copy link

本PR改进了原Knife内部原始的撤销、回退的功能。Knife原有的机制是监听文本变化,然后把修改前的文本存到一个栈里面,undo的时候把栈顶的元素把当前的文本替换掉,而且只会在文本变化的时候进行历史记录。这种做法虽然简单粗暴,但是每次有文本修改,就把整一套文本复制一次,这种做法太低效了,如果文本内容特别大,『能耗』就更高了。

我在内部维护一个栈(CapacityLimitedStack),用于保存每次所做的修改动作(Action),这个栈有一个最大的容量限制(historyMaxCapacity),如果栈满之后继续push,则新action压栈,旧(位于栈底)的Action会被丢弃。

Action是一个接口,也就意味着压栈的所有的Action都是可定制的。不管是文本的变动,还是Span的增删变化,undo和redo都能完美地被支持。

每次undo时,栈顶Action被弹出,他的undo()方法会被调用。
每次redo时,栈顶Action被弹出,他的redo()方法会被调用。

注:Knife的historySize 被更名为 maxHistoryCapacity

@mthli
Copy link
Owner

mthli commented Jan 12, 2016

我 pull 到本地先和 develop 分支合并了。取消 BulletSpan 再 undo 会 crash ;还有 QuoteSpan 的 redo/undo 有时会重复,有时则不会生效。我这边调整一下,再合并到 master 。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants