Add improvments to only format the selection when text is selected, and ...

...to only trigger a document modification if the formatting actually changed anything