我将如何在较大的文本字段中记录更改? [英] How would I go about recording changes in a large text field?

查看:99
本文介绍了我将如何在较大的文本字段中记录更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我希望用户在20分钟内写一个故事.完成用户操作后,我想回放故事编写过程,以便了解用户如何进行操作.我该怎么做?显然,我不想看每一秒钟,但是我想看一下何时进行大更改"的快照. 大变化"应该由我来定义.可能是X个字符的加法或减法.

Let's say I want a user to write a story in 20 minutes. After the user is done I want to play back the story writing process so I can see how the user went about doing it. How would I do this? I don't want to watch every second of it, obviously, but I'd like to see a snapshot of whenever a "large change" was made. The "large change" should be defined by me. It could be X amount of character additions or subtractions.

我想到了以某种方式尝试不断监视文本框的更改,然后在每次大更改"时将文本作为字符串存储在数组中.然后重播此内容,我将延迟1秒播放字符串数组.

I thought of somehow trying to continuously monitor the textbox for changes and then store the text as a string in an array every time there is a "large change". Then to replay this, I will play the string array with a 1 second delay.

有人想到这样做的更好方法,还是知道一个会有所帮助的图书馆?

Anyone think of a better way to do this or know a library that would help?

谢谢!

推荐答案

让我们理所当然的是,您有能力保持这种状态,只看一下检测和显示差异的挑战.您面临的问题中最具挑战性的方面是定义并随后检测到您所说的大变化".如果我们暂时搁置一下,我认为有两种方法可以解决此问题:

Let's take for granted that you have the capacity to persist this state and just look at the challenge of detecting and displaying the diffs. The most challenging aspect of you problem is going to be defining and subsequently detecting what you call a "large change". If we set that aside for a moment I think there are two ways you can go about this:

1)操作转换-(http://en.wikipedia.org/wiki/Operational_transformation)

1) Operational transform - (http://en.wikipedia.org/wiki/Operational_transformation)

这是Google Docs(etherpad)用于跨多个浏览器同步实时协作编辑的内容.使用OT,您几乎可以重新创建对文档所做更改的视频.您可以在thinklinkr.com的修订历史记录中看到这一点(完整披露-我是创始人之一).

This is what Google Docs(etherpad) uses to synchronize real-time collaborative edits across multiple browsers. With OT you can practically recreate a video of the changes made to a document. You can see this in action on thinklinkr.com revision history (full disclosure - I am one of the founders).

2)差异匹配路径-(http://code.google.com/p/google-diff-match-patch/)

2) Diff-match-path - (http://code.google.com/p/google-diff-match-patch/)

这实际上是一组三种算法,可用于有效创建和解决文本文档之间的差异.考虑到您对分块差异的需求,我认为这可能是一个更好的选择.

This is actually a set of three algorithms that can be used to effeciently create and resolve differences between text documents. I think this might be a better match for you given your requirement about chunking diffs.

这篇关于我将如何在较大的文本字段中记录更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆