docs: def _close_widget(widget):
          """
          Closes the given widgets and handles cases where the widget has been
          clone or is a clone of another widget
          """
          if widget is None:
              return
          try:
              widget.document().setParent(None)
              widget.syntax_highlighter.setParent(None)
          except AttributeError:
              pass  # not a QPlainTextEdit subclass
          # handled cloned widgets
          clones = []
          if hasattr(widget, 'original') and widget.original:
              # cloned widget needs to be removed from the original
              widget.original.clones.remove(widget)
              try:
                  widget.setDocument(None)
              except AttributeError:
                  # not a QTextEdit/QPlainTextEdit
                  pass
          elif hasattr(widget, 'clones'):
              clones = widget.clones
          try:
              # only clear current editor if it does not have any other clones
              widget.close(clear=len(clones) == 0)
          except (AttributeError, TypeError):
              # not a CodeEdit
              widget.close()
          return clones