def _adjust_range(self, rng):
        """
        Convert the incoming range (by user) to values relative to the
        input buffer text. Also enforce the modifiable bound.

        :param (int, int) rng: range of selected text
        :return: (int, int): Adjusted range
        """
        terminal = self.stash.terminal
        tv_text = terminal.text  # existing text from the terminal
        length = len(self.chars)  # length of the existing input buffer

        # If the modifiable chars are different from the trailing chars on terminal,
        # this means additional output has been put on the terminal
        # after the event. In this case, simply set the range at the end of
        # the existing input buffer.
        modifiable_string = self.modifiable_string
        lm = len(modifiable_string)
        if lm == 0:
            trailing = u""
        else:
            trailing = tv_text[-lm:]
        if self.debug:
            self.logger.debug("modifiable string: {!r}; length: {!r}; trailing: {!r}".format(modifiable_string, length, trailing))
        assert len(trailing) == len(modifiable_string), len(trailing) - len(modifiable_string)
        if modifiable_string != '' and trailing != modifiable_string:
            xs_adjusted = xe_adjusted = length
        else:
            xs, xe = rng
            # The start location is converted using it offset to the end of the
            # terminal text.
            xs_adjusted = length - (len(tv_text) - xs)
            if xs_adjusted < self.x_modifiable:
                # the selection is invalid because it starts beyond the modifiable input buffer
                xs_adjusted = xe_adjusted = length
            else:
                xe_adjusted = xs_adjusted + (xe - xs)

        return xs_adjusted, xe_adjusted

        Convert the incoming range (by user) to values relative to the
        input buffer text. Also enforce the modifiable bound.

        :param (int, int) rng: range of selected text
        :return: (int, int): Adjusted range
        
system/shstreams.py