by jps on Sun May 31, 2009 12:33 am
In general, if you want to modify the buffer while preserving selections, you need to do it via calls to view.erase(), view.insert(), or view.replace(). These functions preserve the selection, and other state that's relative to positions in the document, such as bookmarks, in-progress snippets, and (in the future) other plugin state.
The next version of Sublime Text will have a findAll() method in the API, so removing all whitespace using the above functions won't be so roundabout.