Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo / Redo and external editing of input text #1506

Open
ibachar opened this issue Dec 16, 2017 · 7 comments
Open

Undo / Redo and external editing of input text #1506

ibachar opened this issue Dec 16, 2017 · 7 comments

Comments

@ibachar
Copy link
Contributor

ibachar commented Dec 16, 2017

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
Copy link
Owner

ocornut commented Dec 17, 2017

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
Copy link
Contributor Author

ibachar commented Dec 17, 2017

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

@ocornut
Copy link
Owner

ocornut commented Dec 17, 2017 via email

@ibachar
Copy link
Contributor Author

ibachar commented Dec 17, 2017

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

@ocornut
Copy link
Owner

ocornut commented Dec 20, 2017

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
Copy link
Owner

ocornut commented Dec 20, 2017

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
Copy link
Contributor Author

ibachar commented Dec 21, 2017

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.

wflohry pushed a commit to wflohry/imgui-addons that referenced this issue Dec 27, 2017
ocornut added a commit that referenced this issue Feb 7, 2024
Very highly requested feature (#6962, #5219, #3290, #4627, #5054, #3878, #2881, #1506, #1216, #968).
Also useful for interactive completion/selection popups (#2057, #718)
Based on @kudaba PR. Design for Inputtext V2 should make this obsolete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants