Add tab-will-change event

When changing tabs, the UPDATEINTERFACE event is send after other events such as textShouldEndEditing: for an active text field are send. This leads to the situation where editing a field in the Palette and changing window-tab while the field still has focus writes the field value to the selected glyphs on the new tab, not the old tab where the edit happened.

Here is a movie to demonstrate:

Shown above are the Guten Tag beta and the Glyphs Notes plugins.

The /N is selected in the font view and the /O in the edit view. When I set a value in the edit view and switch to the font view (while a palette field still has keyboard focus) I expect the edit to be committed on the old tab.

Instead, I get textShouldEndEditing:/textDidEndEditing: with the selected glyphs already pointing to the /N (so the final text value is written to /N). After the text-should/did-end-editing Cocoa-events I get the Glyphs-plugin specific update call, but at this stage it is too late, the value has already been set.

One solution I could see is a tab-will-change event where a plugin can commit any unfinished edits and prepare itself for the new tab.


When I say “selected glyphs” I mean the return value of this code which works for both the font view and edit view:

if font.currentTab:
    return [layer.parent for layer in font.selectedLayers]
else:
    try:
        return font.selection
    except:
        return []