質問

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.

役に立ちましたか?

解決 2

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top