Skip to content

Inkex duplicate() puts duplicate before tail

Summary:

The duplicate() function in Inkex has strange behavior when tails are concerned. If an element has a tail and that element is duplicated, the duplicate is inserted before the original tail. This leaves the original item with no tail and the duplicate with a double version of the original tail. For example, when the following code is run on path798:

el.tail = 'a'
d = el.duplicate();

the following is produced:

image

If the goal of duplicate() is to mimic duplication in base Inkscape, this is unexpected for two reasons:

  1. Base duplication does not duplicate tails at all.
  2. One expects the original item to retain its tail, not for the duplicate to get it.

One workaround would be to change duplicate() to the following:

def duplicate(self):
    selftail = self.tail
    if selftail is not None:
        self.tail = None

    elem = self.copy()
    self.addnext(elem)
    elem.set_random_ids()

    if selftail is not None:
        self.tail = selftail
    return elem

Version info

Inkscape 1.2 (dc2aedaf03, 2022-05-15)

    GLib version:     2.72.1
    GTK version:      3.24.33
    glibmm version:   2.66.4
    gtkmm version:    3.24.6
    libxml2 version:  2.9.14
    libxslt version:  1.1.35
    Cairo version:    1.17.6
    Pango version:    1.50.7
    HarfBuzz version: 4.2.1

    OS version:       Windows 10 21H1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information