<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def insert_before(self, text):
 """ Create a new document, with this text inserted before the buffer. It keeps selection ranges and cursor position in sync. """

        selection_state = self.selection

        if selection_state:
            selection_state = SelectionState(
                original_cursor_position=selection_state.original_cursor_position + len(text),
                type=selection_state.type)

        return Document(
                text=text + self.text,
                cursor_position=self.cursor_position + len(text),
                selection=selection_state)