This fixes a visual bug where the highlighted area wouldn't update when the widget was reshaped, and fixes some weirdness with local functions in preparation for exposing them as part of a rich API for the text widget.