Pause history when adjusting sliders using BatchPlay?
I know that there are other posts on the forum about pausing history states and the solution is to use SuspendHistory() to have multiple changes collapse into one history state, but that assumes that there's a single function that you can call to do it. When giving the user real-time controls, this doesn't work...at least, not how I'm doing it.
I'm working on a panel that uses UXP and BatchPlay to allow the user to modify sliders on their document and each call to BatchPlay is creating an entry in the user's History panel. If I use the Change event on the slider it only puts one history state, but I want the user to see real-time updates by using the Input event when they adjust the slider. This also works okay, but each change in the slider is updating the history states, which is spamming the history panel with hundreds of unnecessary states.
The gist of what I'm doing is:
import { SetContrast } from "../components/AdjustSettings.jsx";
document.getElementById("slideContrast").addEventListener("input", evt => {
this.onSlideContrastInput(evt.target.value);
});
async ChangeContrast(offset) { await SetContrast(offset); }
onSlideContrastInput = (offset) => {
console.log("onSlideContrastInput " + offset);
this.ChangeContrast(offset).then(() => {}).catch(err => {
console.error(err);
});
}AdjustSettings.jsx looks like this:
export const SetContrast = (offset) => {
var intLeft = offset;
var intRight = 255 - offset;
require('photoshop').action.batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_ref": "adjustmentLayer",
"_name": "Contrast"
}
],
"to": {
"_obj": "curves",
"adjustment": [
{
"_obj": "curvesAdjustment",
"channel": {
"_ref": "channel",
"_enum": "channel",
"_value": "composite"
},
"curve": [
{
"_obj": "paint",
"horizontal": intLeft,
"vertical": 0
},
{
"_obj": "paint",
"horizontal": intRight,
"vertical": 255
}
]
}
]
},
"_isCommand": false,
"_options": {
"dialogOptions": "dontDisplay"
}
}
], {
"synchronousExecution": true,
"modalBehavior": "execute"
});
}
Ideally, I'd like to turn off history logging until the Change event fires, which means that that user has stopped moving the slider. Is there a way to do this? Based on what I'm seeing on other threads here, it doesn't look like it--but with how much sliders are used in Photoshop (and in other apps) I can't believe this hasn't been addressed already. Internally I know their own panels do this for their sliders and things like Nudge, etc.
I would even be happy with something like a history state starting when the user starts interacting with the panel and ending when the panel loses focus...if something like that is even possible. I'm thinking that it might be possible to have a modal dialog appear as a single history state, but panels???
Any suggestions? How do existing panels/plugins with real-time sliders handle this? (...or do they?)
