Are there libraries for efficiently editing large lines in Javascript?

I need to efficiently edit large text documents (e.g. source code files) in javascript.

insertAtPosition(n, str)and deleteAtPosition(n, length)should be fast.

A naive line implementation is slow because each operation requires copying the contents of the document to a new line.

There are several effective ways to do this. I could use an array of strings ( Ace , since Bespin does this), but it will be slow when there are super long strings or many short strings. A better implementation would be to use skip lists or some other smart data structure.

But I would expect someone to have done this already.

Are there any libraries that already do this? I cannot find anything useful with Google - is there a common name for this problem?

+5
source share
1 answer

I don’t think there are other libraries for this, so I myself implemented this using the skip lists. It may be faster to use the tree data structure, but skip lists are easy to implement, and closing compiled javascript is only 2.5 KB.

If anyone else has the same problem, enjoy:

https://github.com/josephg/jumprope

+2
source

All Articles