'Change the part we\'re currently completing in the commandline.
Args:
text: The text to set (string) for the token under the cursor.
before: Commandline tokens before the token under the cursor.
after: Commandline tokens after the token under the cursor.
immediate: True if the text should be completed immediately
including a trailing space and we shouldn\'t continue
completing the current item.'

def _change_completed_part(self, newtext, before, after, immediate=False):

    text = (self._cmd.prefix() + '    '.join((before + [newtext])))
    pos = (len(text) + (1 if immediate else 0))
    if after:
        text += ('    ' + '    '.join(after))
    elif immediate:
        text += '    '
    log.completion.debug("setting    text    =    '{}',    pos    =    {}".format(text, pos))
    self._cmd.setText(text)
    self._cmd.setCursorPosition(pos)
    self._cmd.setFocus()
    self._cmd.show_cmd.emit()
