Sublime Forum

Collapsation of regions or lack theoreof


I’m a bit confused about a view object manages its regions when it comes to contiguous regions.

Obviously, regions that overlap with an intersection of length > 0 are blended together; for example:

view.sel().add(Region(0, 10))
view.sel().add(Region(5, 15))
print(list(view.sel()))  # >> [(0, 15)]

Next, a region of length 0 added right next to a region of length > 0, or vice-versa, also causes the region of length 0 to be sucked into the region of length > 0:

view.sel().add(Region(5, 10))
view.sel().add(Region(5, 5))
print(list(view.sel()))  # >> [(5, 10)]

But (!) a zero-length region can be created at the edge of a region of length > 0 by first creating two contiguous regions of nonzero length, and erasing the smaller one:

view.sel().add(Region(5, 10))
view.sel().add(Region(10, 15))
view.erase(edit, Region(5, 10))
print(list(view.sel()))  # >> [(5, 5), (5, 10)]

Now I am kinda-sorta wondering whether this last behavior is not maybe a bug of the API. I have at least three reasons for this suspicion:

  1. The behavior observed above, whereby simply adding a (5, 5) regions next to a (5, 10) region results in the (5, 5) region simply being sucked into the (5, 10) region

  2. I could not find a way of creating a configuration of regions such as [(5, 5), (5, 10)] via the mouse/GUI

  3. Once a configuration of regions like [(5, 5), (5, 10)] is created as above, typing a single character, say ‘z’, results in two z’s being inserted, but also in the two regions collapsing to a single region of length 0 coming after the two z’s; whereas the more “logical” outcome, it seems to me if configurations like [(5, 5), (5, 10)] were really meant to be supported, would be for two separate regions (i.e., two carets) to remain, one after each z

Is there some deeper logic that I am missing? Is the choice of allowing region combinations such as [(5, 5), (5, 10)] intentional? Then why the devious workaround to create such a combination?