code: def insert_before(self, text):
          
          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)
docs: Create a new document, with this text inserted before the buffer.
          It keeps selection ranges and cursor position in sync.