def join_selected_lines(self):
        """
        Join the selected lines.
        """
        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(' ') + ' ' for l in lines]

        # Set new document.
        self.document = Document(text=before + ''.join(lines) + after,
                                 cursor_position=len(before + ''.join(lines[:-1])) - 1)
dataset/ETHPy150Open jonathanslenders/python-prompt-toolkit/prompt_toolkit/buffer.py/Buffer.join_selected_lines/original