Don't modify buffer in document visibility change handler if not connected
Merge pull request #248 from lorenzhs/fixnull

Don't modify buffer in document visibility change handler if not connected