查找行数&字符串更改时索引移动的字符
当包含单词的字符串发生更改时,是否有某种算法(或其 JavaScript 实现)可以找到单词位置的移动量?
我的项目是一个基于 CodeMirror 的在线编辑器,当使用 MobWrite 协作服务将新数据添加到代码中时,我需要重新定位光标。
因此,要将光标位置设置为当前用户正在编辑的单词,我想我需要计算其位置和位置的移动量。将其添加到原始光标位置。
解决方案: 现在,我正在尝试实现 MobWrite 使用的方法。
谢谢大家的帮助。
Is there some algorithm(or its JavaScript implementation) to find the amount of shift in a word's position when the string containing the word was changed?
My project is an online editor based on CodeMirror where I need to re-position the cursor when new data has been added to the code using the MobWrite collaboration service.
Therefore, to set the cursor-position to the word that the current user was editing, I think I need to calculate the amount of shift in its position & add that to the original cursor-position.
Solution:
Now, I'm trying to implement the method used by MobWrite.
Thank you all for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要这个: http://en.wikipedia.org/wiki/Levenshtein_distance
在该页面上是其他距离类型。检查它们是否更能满足您的需求。
You probably want this: http://en.wikipedia.org/wiki/Levenshtein_distance
On that page are other distance types. Check if they meet your need better.
MobWrite 实现的解决方案相当全面&可以在这里找到:http://neil.fraser.name/writing/cursor/ 。
我实际上试图解决的问题的解决方案可以在这里找到: 让 CodeMirror 跟随 TextArea
The solution implemented by MobWrite is quite comprehensive & can be found here: http://neil.fraser.name/writing/cursor/ .
The solution to the problem I was actually trying to solve can be found here: Getting CodeMirror to follow a TextArea