Can't we do something similar to what you're doing here inside `TextBuffer` itself? Then at least we're making a single API call instead of making assumptions about structure.