Are programmed undos able to work across layers?



  • I'm noticing undos don't seem to work across layers. When I execute the following script and try to cmd+z on the foreground, it undoes what was done before the script was run. cmd+z in background layer does not have an undo history. Previous state of background seems to be wiped.

    Doesn't work:

    g = CurrentGlyph() 
    
    with g.undo('Put current glyph in background'):
        fore = g.getLayer('foreground')
        back = g.getLayer('background')
        back.clear()
        back.appendGlyph(fore)
        back.width = fore.width
        back.update()
        g.update()
    

    Works:

    g = CurrentGlyph() 
    
    fore = g.getLayer('foreground')
    back = g.getLayer('background')
    with back.undo('Put current glyph in background'):
        back.clear()
        back.appendGlyph(fore)
        back.width = fore.width
        back.update()
        g.update()
    

  • admin

    hello @ryan,

    this is the expected behavior of undo: it is glyph based, and each layer is a separate glyph. the first example doesn’t work because you’re only recording changes to the default layer: CurrentGlyph() is equivalent to CurrentGlyph().getLayer(CurrentFont().defaultLayer.name).

    hopes this makes sense…

    ps. glyph.update() is deprecated in RF3, use glyph.changed() instead.



  • Hi @gferreira Thanks for the explanation. This certainly makes sense structurally. I'm now wondering if something like this could be made possible in extensions, in cases where the user might expect to be able to undo a whole, somewhat complex action that moves across layers.

    Thanks for letting me know about the method deprecation!


  • admin

    For maximum flexibility each glyph has his own undo manager. You dont want to use a single undo manager for everything. I understand in this case a single cmd-Z should perform actions in multiple glyphs.

    A while ago Ive made dirty hack... let me see if I can clean it up.


Log in to reply