How to handle cancel during long editDocument()?

See if this maybe helps How to handle the 'Stop' button event when 'plugin is working...'? - #6 by mightyalex.