iOS vs macOS: Updating the selection object reference passed to Plugin menu and plugin toolbar button handlers after a scripted change of selected canvas:
Problem / difference:
If a URL-launched (or console-executed) script
- Creates a new canvas, and
- selects it with a line like:
document.windows[0].selection.view.canvas = newCanvas;
On macOS the selection object passed to Plugin menu and toolbar - button handlers is immediately and correctly updated, so that functions invoked with plugin widgets get the expected reference to the newly selected canvas.
On iOS the selection object is not immediately updated, and still refers to the canvas that had the selection before the script ran, so that Plugin menu items and plugin toolbar button functions either fail, or attempt to produce effects in the wrong canvas.
(The selection object passed to plugin events is not updated until the user manually unselects and then reselects the new (script created and script-selected) canvas in the GUI.
Builds:
macOS: OmniGraffle 7.4 test (v179.5 r291208
iOS: OG 3 179.8.0.291436
Test:
First, script:
- The creation of a new canvas and a couple of shapes
- The setting of the front window selection to this new canvas
Then, try to use a plugin menu or a plugin button on the toolbar.
This will work on macOS, but fail on iOS. On iOS the plugin will be passed a reference to the previously selected (pre-script run) canvas.
On iOS, plugins won’t work in these circumstances until you manually take focus away from the new canvas, and then manually return it (though GUI interactions).
Test script:
(function () {
'use strict';
// 1. NEW CANVAS WITH 2 LINKED SHAPES
// 2 MAKE IT THE CANVAS SELECTED IN THE FRONT WINDOW
var
newCanvas = addCanvas(),
dctShapeStyle = {
shape: "Circle",
cornerRadius: 5,
shadowColor: null,
strokeColor: Color.RGB(
0.647058844566345, 0.647058844566345, 0.647058844566345
),
magnets: [new Point(0.00, 1.00), new Point(0.00, -1.00)],
},
shpA = Object.assign(
newCanvas.newShape(),
dctShapeStyle, {
geometry: new Rect(100, 100, 50, 50),
}
),
shpB = Object.assign(
newCanvas.newShape(),
dctShapeStyle, {
geometry: new Rect(200, 200, 50, 50)
}
);
Object.assign(
newCanvas.newLine(), {
strokeThickness: 2,
tail: shpA,
lineType: LineType.Curved,
head: shpB,
shadowColor: null,
strokeColor: Color.RGB(1.0, 0.149131417274475, 0.0)
}
);
// SCRIPTED CHANGE OF SELECTED CANVAS
document.windows[0].selection.view.canvas = newCanvas;
// Now try to use a plugin menu or toolbar item.
// On iOS, the plugin widgets will still get the wrong selected canvas,
// until you manually toggle the selection in the GUI.
// On macOS, the plugin widgets are immediately getting a reference
// to the newly selected canvas.
})();