I'm dealing with a related issue, and here's how I understand it: this is neither a bug nor a feature, but a misunderstanding of the metaphor. There's no such thing as "text that has associated regions." You can use view.add_regions (which is what I assume you're talking about) to add a set of *regions* to a view under a particular key, but that has nothing to do with *text.* Regions are locations in the file.
Let's say I have a buffer that just contains the text "foobar". I'm doing the following in the console:
- Code: Select all
>>> a = sublime.Region(0, 3)
>>> a
(0, 3)
# Note that this isn't text at all. Just locations.
>>> view.substr(a)
u'foo'
# I can use those locations to get the text occupying that space *from the view.*
# Now, if I delete "foo", so that the buffer just contains "bar":
>>> view.substr(a)
u'bar'
>>> a
(0, 3)
# a (the Region) hasn't changed, but the contents of that Region have.
It's like the difference between addresses and people. view.add_regions allows you to set up a list of addresses, just like if you had a mailing list. But if a family moves, their old house stays at the same address, and so sending a letter to 123 Whatever Blvd will still go to the same place, whether they live there or not.
So: Regions are *supposed* to be independent of text, and so shouldn't be changed if the text is.
I think what we're both wanting, though, is to have something like mail forwarding (metaphorically, not programmatically), such that we can identify a span of text in a buffer with which we can associate data that will persist even if the location of that text changes. I can see, though, how this could be a programming nightmare, and I'm not sure at all how I'd go about implementing it myself. I'm hoping there's something in place that can simulate that, though. Maybe?