Update the highlighting.

        This is an overloaded version of the native Qt slot of
        ``QTextEdit``.

        In this class, the purpose of this slot is to check if the
        character to the right of the cursor needs highlighting,
        assuming there is a second character to pair with it.

        |Args|

        * **None**

        |Returns|

        * **None**

        |Raises|

        * **None**

def cursorPositionChangedEvent(self):
        """
        Update the highlighting.

        This is an overloaded version of the native Qt slot of
        ``QTextEdit``.

        In this class, the purpose of this slot is to check if the
        character to the right of the cursor needs highlighting,
        assuming there is a second character to pair with it.

        |Args|

        * **None**

        |Returns|

        * **None**

        |Raises|

        * **None**
        """

        # Determine the sender and cursor position.
        qteWidget = self.sender()
        tc = qteWidget.textCursor()
        origin = tc.position()

        # Remove all the highlighting. Since this will move the
        # cursor, first disconnect this very routine to avoid an
        # infinite recursion.
        qteWidget.cursorPositionChanged.disconnect(
            self.cursorPositionChangedEvent)
        self.qteRemoveHighlighting(qteWidget)
        qteWidget.cursorPositionChanged.connect(
            self.cursorPositionChangedEvent)

        # If we are beyond the last character (for instance because
        # the cursor was explicitly moved to the end of the buffer)
        # then there is no character to the right and will result in
        # an error when trying to fetch it.
        if origin >= len(qteWidget.toPlainText()):
            return
        else:
            # It is save to retrieve the character to the right of the
            # cursor.
            char = qteWidget.toPlainText()[origin]

        # Return if the character is not in the matching list.
        if char not in self.charToHighlight:
            return

        # Disconnect the 'cursorPositionChanged' signal from this
        # function because it will make changes to the cursor position
        # and would therefore immediately trigger itself, resulting in
        # an infinite recursion.
        qteWidget.cursorPositionChanged.disconnect(
            self.cursorPositionChangedEvent)

        # If we got until here "char" must be one of the two
        # characters to highlight.
        if char == self.charToHighlight[0]:
            start = origin
            # Found the first character, so now look for the second
            # one. If this second character does not exist the
            # function returns '-1' which is safe because the
            # ``self.highlightCharacter`` method can deal with this.
            stop = qteWidget.toPlainText().find(self.charToHighlight[1],
                                                start + 1)
        else:
            # Found the second character so the start index is indeed
            # the stop index.
            stop = origin

            # Search for the preceeding first character.
            start = qteWidget.toPlainText().rfind(self.charToHighlight[0],
                                                  0, stop)

        # Highlight the characters.
        oldCharFormats = self.highlightCharacters(qteWidget, (start, stop),
                                                  QtCore.Qt.blue, 100)

        # Store the positions of the changed character in the
        # macroData structure of this widget.
        data = self.qteMacroData(qteWidget)
        data.matchingPositions = (start, stop)
        data.oldCharFormats = oldCharFormats
        self.qteSaveMacroData(data, qteWidget)

        # Reconnect the 'cursorPositionChanged' signal.
        qteWidget.cursorPositionChanged.connect(
            self.cursorPositionChangedEvent)