Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

function for undo/redo

Explorer ,
Sep 10, 2020 Sep 10, 2020

Hi there,

I have a JSX file that has multiple scripts that I have built. I am hoping there is a way to build a undo/redo function that I can use inside each script. 

Example. I have a panel that when I click a button for branding the text to my companies font. if I want to undo this I have to undo multiple times, to remove hyphenation, color, size, text_align, etc. then it goes back to the original before the script runs. I saw some people post a function that wraps your script, but the problem I have would be that the HTML file is looking for the function that would be inside the undo function.

Since I have so many different scripts I was hoping I could do something like the following.

function textChange() {
//style font
undoRedo();
}

function undoRedo() {
//way to ask which function script to redo
}

 

Is this possible?

TOPICS
Scripting
612
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2020 Sep 10, 2020

Hi There,

It does not work exactly the way you want, but what you can do is wrap the whole operations of a script or function into a single step for undo. So if you call multiple functions/scripts using this way each of these functions/scripts would have a single entry on the undo/redo stack. Play around with the following operations you will get an idea of what can be done

app.doScript()

app.undo()

document.undo()

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2020 Sep 10, 2020

okay, I will give these a try. do you know if there is a way to merge the history of layers that are created in the script into one history? This way undo only has to be hit once.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2020 Sep 10, 2020
LATEST

The only way to squash history of multiple versions into a single is the doScript method. However, that includes all the operations done in the function/script passed to it and is not restricted to just the layer operations. So the idea for you would be to isolate the operations that you want to be logically connected into a function and call that function using doScript method, In such a case all these operations would then be eligible to be reverted back in a single undo.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines