JavaScript: data set for a large string (text document)
===

I'm writing a text editor and I need to deal with large documents (50000+ characters).

The document will be split into __paragraphs__ which can have one or more __lines__.

    <div class="paragraph">
      <div class="line"> ... some text ... </div>
      <div class="line"> ... some text ... </div>
    </div>

Let's say we have a large string (over 50K chars), the splitting will be as follows:

 - each __/n__ (new line) will split the string into '__paragraph__' strings
 - each paragraph will be split into '__line__' strings based on word wrapping


__What data set/structure will be efficient to use with this paradigm?__

Also this keep in mind it would require the following actions to be fast:

 - retrieving a range of characters: `getString(4522, 4529)`
 - insert char: `insert(4779, 'd')`
 - delete char: `delete(4521, 4524)`
 - search a word/string

Basically it would require to work with character position, ex: http://i.stack.imgur.com/sCYFf.png

I've looked at how code editors handle this, they use a B-tree data structure, but wondering if someone would recommend a better structure and how to handle insert/delete.

I appreciated any feedback, thank you