Clicking any button on any UXP panel inactivates keyboard shortcuts for tools and brush sizes

@AnthonyK, yes me too, actually.
setTimeout didn’t help here…

It should be possible to choose between the “performMenuCommand()” method for Windows and the UXP modal dialog method for Mac using require('os').platform().

Not terribly elegant, but when you get desperate, any workable hack looks better than nothing.

@Pierre_G
Can you please check on Mac method with open and close UXP modal window, which I described early?

Yes sure. Which one in particular?

@Pierre_G Thanks!
Please see my first message on this topic.

@Alexandr_Stroganov and @Pierre_G . The open/close of a UXP dialog modal method works on Mac to restore focus to Photoshop. At least it did for me yesterday and today. With Mac, I’m never sure when things are going to change.

1 Like

Thanks for the information!

@AnthonyK @Pierre_G
A friend of mine recently bought a Mac and has kindly given me access through the Team Viewer for focus tests. And I have great news again, I found a solution that is more aesthetic than uxpOpen/uxpClose window.

function menuCommand(id) {
   require('photoshop').core.performMenuCommand({
     commandID: id,
     kcanDispatchWhileModal: true,
     _isCommand: false
   });
 }

menuCommand(2982);
menuCommand(2986);
menuCommand(2986);

id 2982: Filtered layers by ‘Name’ property in the Layers Panel.
Already here the focus is returned to Photoshop, but you need to enter the name of the layer.
Thus, we need to reset focus from this input field.

id 2986: Filtered layers by ‘Selected’ property in the Layers Panel and re-using this command to filter the layers back to the original property '‘Kind’.

This worked great on Mac for me. Also, I tested this method on Windows now and there is a small 1 frame animation in the Layers Panel. But since I’m running tests through the team viewer on Mac with a reduced frame rate per second, I can’t figure out if there is animation or not.
Can you please check it?

A side effect of breaking the user-level filtering setting if it is not set by default.
But in all my time in Photoshop, I rarely used this feature.

1 Like

That worked on Windows.

However, I wonder if it’s actually better than menuCommand(1208) given that “1208” is completely invisible on Windows. There is a brief flicker at the top of the layers panel on Windows with

menuCommand(2982);
menuCommand(2986);
menuCommand(2986);

Regardless, this seems like a workable solution. The flicker is certainly less annoying than the brief appearance of the “Close” button of the dialog window.

Do you know whether menuCommand(id) should be an async/await function?

I prefer to use 1208 for Windows and for Mac the second method, but as I said, I still cannot understand if the animation is on the Mac, but with low FPS I still don’t see it.

I just like you wondered about this question. I tested both options on windows and they both work.

I also used your method of determining the current user’s system require('os').platform();
My system was defined in the console as ‘win32’ and my friend’s Mac system was ‘darwin’.

I’m trying to figure out if there will always be only these two values, or can we come across for example ‘win64’ or another option for Mac?

On my MacBook Air (Intel-based) that I use for testing, there is a very brief flicker as the

menuCommand(2982);
menuCommand(2986);
menuCommand(2986);

commands execute.

I’d say it’s even shorter than on my Windows computer, but I see it on both platforms.

If we find a command that just sets the Kind parameter, flicker can be avoided.
But I tried many different IDs and couldn’t find other types of filters in the Layers panel.

It is also possible to try to reset the focus from the text input field in a different way after 2982, but it is very difficult to reset.

Hello all,
Glad to have found a thread regarding this issue! Though, it’s been about a year since the last reply here - am I missing something obvious that has resolved this focus issue?

I’m on a Mac, PS 2022, and haven’t been able to get a reliable fix to return focus to the app. The closest seems to be menuCommand 5593, which returns focus, but tiles any open documents.

menuCommand(2982) by takes focus away from the panel, but gives it to the text input field.

(2982) + (2986) + (2986) returns filtering to the Kind parameter, but focus again ends up being on the panel. Ahhhhh, so close!!

Alexandr, I certainly appreciate all of your troubleshooting to find a solution! However, it sounds like menuCommands are liable to change and may not be consistent for all users (seems like I read that on the forum). This seems like an issue that shouldn’t require a workaround and a prayer… Perhaps I missed an update… or are you guys still dealing with this?

I think this got fixed when Ps 2022 was released last October. My focus-returning code is set to execute only if Ps 2021 is running.

1 Like

You might be able to verify if it’s still happening by creating a style for when the panel has focus:

.myPanel:focus {
    border: 2px solid red;
}

If you can confirm it has focus then wherever you’re calling app.bringToFront() try a few different options:

document.blur();
window.blur();
myinput.blur();

or try redispatching the event:

function myKeyboardHandler(event) {
    // my code
    app.bringToFront();
    document.dispatchEvent(event);
    window.dispatchEvent(event);
}

Thanks for the feedback @AnthonyK and @Velara.

Good call on styling the focus. Made me realize it’s not a focus issue I’m looking at - it’s only that Undo is greyed out after interacting with any UXP panel (my own panel, Alchemist, Hello World Sample). When I click outside the panel, Undo reappears as an option.

Just updated Photoshop and reset prefs, same thing.

So if anyone has a sec, I might reframe the question - anyone having problems with Undo?

I noticed this as far back as March 2020 with CEP panels and filed a bug report with Adobe.

The bug was:

“Click a button that runs a JSX script from a third-party extension panel. One that will generate a history state as a result of running the script.”

However, I don’t see the problem all the time with my UXP plugins.

Try turning off the code that returns focus to Ps and see if that helps.

Also, does your plugin use and JSX script? That seemed to be the problem with CEP.