editor: fixing grid to handle changes to the document when grid is turned on