fixed crash in TextDocument

Signed-off-by: Konctantin <gawrilyako@gmail.com>