code: def join_selected_lines(self, separator=' '):
          
          assert self.selection_state
  
          # Get lines.
          from_, to = sorted([self.cursor_position, self.selection_state.original_cursor_position])
  
          before = self.text[:from_]
          lines = self.text[from_:to].splitlines()
          after = self.text[to:]
  
          # Replace leading spaces with just one space.
          lines = [l.lstrip(' ') + separator for l in lines]
  
          # Set new document.
          self.document = Document(text=before + ''.join(lines) + after,
                                   cursor_position=len(before + ''.join(lines[:-1])) - 1)
docs: Join the selected lines.