The selection
property of a document stores selected objects. In text editing mode, selection stores the TextRange
, so selection = null
does not deselect the text object itself, but resets the selected character range.
If we need to stop editing text and select some object of the document, there appears a bug that the object is selected and the cursor in the text is active. It is impossible to reproduce it manually.
selection = null;
app.activeDocument.pageItems[0].selected = true;
In Illustrator CS6 and above, it is possible to call menu commands through app.executeMenuCommand()
. So you can deselect the text you are editing with the Select → Deselect menu command.
app.executeMenuCommand("deselectall");
app.activeDocument.pageItems[0].selected = true;
In CC 2020 there is a command for switching tools app.selectTool
. So another way: switch the active Type Tool to any other one and then selection = null
will reset the selection exactly from the text object. The method is not suitable for previous versions of Illustrator, but has the right to life.