Selecting objects when editing text

The script command reset the selection, but the cursor is active
selection = null;
app.activeDocument.pageItems[0].selected = true;
Rectangle is selected, but the text is still editable
app.executeMenuCommand("deselectall"); app.activeDocument.pageItems[0].selected = true;
Exit text editing with the menu command
Exit text editing by switching the tool

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store