godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Allow TextEdit/CodeEdit Undo Stack & State to be Synced Wit Another #10241

Open anatoli-dp opened 4 months ago

anatoli-dp commented 4 months ago

Describe the project you are working on

An IDE for a custom game console to allow scripting, sprite editing, and sound generation bb_ide

Describe the problem or limitation you are having in your project

currently in order to be able to "sync" changes between two tabs I override one script with another via removing text and adding the updated one as a complex action . . .

screen

initially i thought this would allow me to be able to undo just that change but it doesn't, i have to "undo" twice to remove each character update as well as the editor jumping to the top and bottom of the page for each edit even if the undo was in the middle of the script. So to be able to mimic both tabs acting the same with the same undo stack i have to use one editor as a proxy and swap it to the active one while taking the characteristics of the proxy (scroll location and cursor location when swapping) and make the previous active one the new proxy . . . which is a lot of headache for just wanting both code edit/text edit to share the same state (this allows me to have two editors open with the same script so i can reference one part of the script in one editor while making changes in the other so user doesn't have to scroll through the script constantly if wanting to look at one function while implementing another)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

what would be great is allow the undo stack to be able to both be set and retrieved from the editor. This allows for a very nice enhancement that can be piggybacked upon to allow custom actions like my issue above. Being able to both grab and set the built in undo stack and stack position will allow it to be saved when a project is reopened (so u have an editor and close it out, but when u reopen it the stack can be loaded so u can undo operations u did the day before and essentially be able to pick up right where u started including undo history). With this ability one can be able to set the state between editors as well by setting the text and then the undo stack and pointer essentially being able to "sync" the actions from one editor to the other.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

within TextEdit the stack is saved as two lists

List<TextOperation> undo_stack;
List<TextOperation>::Element *undo_stack_pos = nullptr;

exposing both of these to gdscript to set and grab would be all thats needed (though i imagine some data mutation will also be needed in order to better send and retrieve it from gdscript itself. so saying "all thats needed" may be a bit misguided as i am only just now looking into how internal stuff is done in the engine).

it could just be regular properties of TexEdit

undo_stack: Array
 - get_undo_stack() -> stack: Array
 - set_undo_stack(stack: Array)
undo_stack_position: Int (int in here as gdscript doesnt support pointers . . . but the number would represent which element is the pointer pointing to)
 - get_undo_stack_position() -> position: int
 - set_undo_stack_position(position: int)

If this enhancement will not be used often, can it be worked around with a few lines of script?

it could be recreated if one recreates their own UndoRedo as the class does exist in the docs . . . but then u have to include everything to mirror the built in one to have the same ability as well as bind the button commands to it and hope the built in one doesnt trigger . . . if it can be done with only a few lines i am not sure as i didnt exactly understand the UndoRedo fully and would have to be fighting the built in one as well to override it with the custom one (if this can already be done please let me know as i have been struggling with this)

Is there a reason why this should be core and not an add-on in the asset library?

TextEdit and CodeEdit are built in nodes and having their stack exposed would be something that is more of a built in ability than something that is extra like a add-on. it is a core part of that node.

anatoli-dp commented 4 months ago

in the problems section there is more work than just making one of the editors a proxy, it is also keeping track of active ones for each script open when there are duplicates. It just creates a lot of uneeded spaghetti code to be able to mimic that action without really being able to . . .