Selecting objects when editing text

AiScripts
2 min readMar 7, 2022

--

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.

The script command reset the selection, but the cursor is active

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;
Rectangle is selected, but the text is still editable

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;
Exit text editing with the menu command

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.

Exit text editing by switching the tool

Let me know if it was helpful to you. You can find me: Facebook / Github / Telegram

--

--

AiScripts
AiScripts

Written by AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts

No responses yet