Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The trick is to decouple the concept of 'position' in the text, that is independent of the gap, from 'pointer' into the buffer. If you keep track of line beginnings as positions, you can immediately get the pointers:

  ptr = pos if pos<=gapstart else pos + gapsize


Replying to myself: it's actually a bad idea because you have to update all indices at each inserted char! Forget about it...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: