def apply_change(self, change):
text = change['<STR_LIT:text>']<EOL>change_range = change.get('<STR_LIT>')<EOL>if not change_range:<EOL><INDENT>self._source = text<EOL>return<EOL><DEDENT>start_line = change_range['<STR_LIT:start>']['<STR_LIT>']<EOL>start_col = change_range['<STR_LIT:start>']['<STR_LIT>']<EOL>end_line = change_range['<STR_LIT:end>']['<STR_LIT>']<EOL>end_col = change_range['<STR_LIT:end>']['<STR_LIT>']<EOL>if start_line == len(self.lines):<EOL><INDENT>self._source = self.source + text<EOL>return<EOL><DEDENT>new = io.StringIO()<EOL>for i, line in enumerate(self.lines):<EOL><INDENT>if i < start_line:<EOL><INDENT>new.write(line)<EOL>continue<EOL><DEDENT>if i > end_line:<EOL><INDENT>new.write(line)<EOL>continue<EOL><DEDENT>if i == start_line:<EOL><INDENT>new.write(line[:start_col])<EOL>new.write(text)<EOL><DEDENT>if i == end_line:<EOL><INDENT>new.write(line[end_col:])<EOL><DEDENT><DEDENT>self._source = new.getvalue()<EOL>
Apply a change to the document.