Undo / Redo and external editing of input text #1506

Open
opened 2017-12-16 13:37:12 +00:00 by ibachar · 7 comments
ibachar commented 2017-12-16 13:37:12 +00:00 (Migrated from github.com)

Hi,

I've an issue with text editing. In my editor, I have my own implementation of undo / redo.
I've managed to disable undo / redo feature in text input by modifying the code (couldn't find a flag)
The issue is that the value returns to its current value after undoing if the text input is active (since the text input stores a cache of the passed values). Is there a way to invalidate the cache while the text input is active?

Thanks

Hi, I've an issue with text editing. In my editor, I have my own implementation of undo / redo. I've managed to disable undo / redo feature in text input by modifying the code (couldn't find a flag) The issue is that the value returns to its current value after undoing if the text input is active (since the text input stores a cache of the passed values). Is there a way to invalidate the cache while the text input is active? Thanks
ocornut commented 2017-12-17 09:14:43 +00:00 (Migrated from github.com)

Hello,
It’s an unsolved issue at this point. We can add the flag to disable the undo/reso handling of InputText(), but it will still own the text data while active. I am currently away without a computer but I think you might be able to get away by manipulating the internal activeid during your own undo operation. Try ClearActiveID in imgui_internal.h. But then you will lose your widget focus.

Also browse the issues with the same flag because it has been discussed at least once here.

Hello, It’s an unsolved issue at this point. We can add the flag to disable the undo/reso handling of InputText(), but it will still own the text data while active. I am currently away without a computer but I think you might be able to get away by manipulating the internal activeid during your own undo operation. Try ClearActiveID in imgui_internal.h. But then you will lose your widget focus. Also browse the issues with the same flag because it has been discussed at least once here.
ibachar commented 2017-12-17 09:23:16 +00:00 (Migrated from github.com)

Ok. Thanks. I also though about maybe calling PushID with the current undo stack size.

Ok. Thanks. I also though about maybe calling PushID with the current undo stack size.
ocornut commented 2017-12-17 09:46:16 +00:00 (Migrated from github.com)

That’s an original solution! I hadn’t thought about it, it might work just as well.

That’s an original solution! I hadn’t thought about it, it might work just as well.
ibachar commented 2017-12-17 13:31:53 +00:00 (Migrated from github.com)

I've created a pull request with a new flag to disable undo. #1508

I've created a pull request with a new flag to disable undo. #1508
ocornut commented 2017-12-20 15:27:52 +00:00 (Migrated from github.com)

I've merged your PR with tweaks and an additional, however this issue isn't fully resolved as we ought to provide a more obvious way to allow for an external undo stack to be applied on text fields, other than using PushId or ClearActiveId. Preserving cursor/selection may be a bit tricky there.

I've merged your PR with tweaks and an additional, however this issue isn't fully resolved as we ought to provide a more obvious way to allow for an external undo stack to be applied on text fields, other than using PushId or ClearActiveId. Preserving cursor/selection may be a bit tricky there.
ocornut commented 2017-12-20 15:29:15 +00:00 (Migrated from github.com)

I ought to clarify: in my previous game engine, CTRL-Z/Y was left to the active input text, and only passed to the engine undo stack based on the io.WantCaptureKeyboard flag. So there would technically be 2 undo stacks in action but it worked ok.

I ought to clarify: in my previous game engine, CTRL-Z/Y was left to the active input text, and only passed to the engine undo stack based on the `io.WantCaptureKeyboard` flag. So there would technically be 2 undo stacks in action but it worked ok.
ibachar commented 2017-12-21 06:25:13 +00:00 (Migrated from github.com)

That would work but my undo behaviour is a bit different from what is implemented in the text input. Undoing doesn't delete text letter by letter but instead revert to the state when the text input got focused (this is the behavour in most editors). I do this by tracking if the text is active and then store the current value once it becomes active.
Also, the workaround I proposed above (with PushID) didn't work since once the user inserts a letter, my undo stack size changes causing the text input to lose focus.

That would work but my undo behaviour is a bit different from what is implemented in the text input. Undoing doesn't delete text letter by letter but instead revert to the state when the text input got focused (this is the behavour in most editors). I do this by tracking if the text is active and then store the current value once it becomes active. Also, the workaround I proposed above (with PushID) didn't work since once the user inserts a letter, my undo stack size changes causing the text input to lose focus.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#1506
No description provided.