The following bit changed before I moved it from Editor to Document - the change is to sort the selections before returning them. I decided to use the lodash `chain` feature to make it a bit more legible.