Fix a bug with calculating local scope when adding characters at the end of the file.