Why is the SEL_DELETED message sent before the actual deletion?
SEL_DELETED is sent so as to afford the target of the message a chance to save the text that existed prior to the removal; this is useful for the purpose of maintaining undo list. Since the SEL_DELETED message contains the information about the to-be-deleted stuff, its a small matter to determine what the state of the widget will be after the deletion, should it be necessary.