Skip to content

How to check for backspace key/event in TextInputMultiline callback (CallbackEdit flag) #8545

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

Open
inflex opened this issue Apr 2, 2025 · 2 comments

Comments

@inflex
Copy link

inflex commented Apr 2, 2025

Version/Branch of Dear ImGui:

1.91.9

Back-ends:

SDL2 software

Compiler, OS:

linux + gcc

Full config/build information:

No response

Details:

I'm working on a simple wordwrap for InputTextMultiline for use with monospace fonts and so far "most" things are going well except for when I start backspacing across prior linebreaks ( this is due to the codec being used creating \r\n instances to represent hard-breaks, so backspacing then produces a sole \r ).

My question is, where/how can I capture the backspace keypress and is it available within the callback so that I can properly test for and handle this corner case?

While I can see the callback being invoked during with the backspace press if I have the ImGuiInputTextFlags_CallbackEdit, I however cannot see where I can detect if it was the backspace key that induced that, neither data->EventKey or data->EventChar indicate anything for me.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Apr 2, 2025

We cannot provide the info in EventKey for ImGuiInputTextFlags_CallbackEdit as multiple edits may have happened.

You could technically simply poll the key on that event, but the edit will have been done already, and it feels a bit like a quagmire to think you can reliably reconstruct a sequence of event and patch a text buffer this way.

Generally speaking, I'm not super comfortable moving forward with this that as:

  • word-wrapping is not yet supported and I don't think pre-wrapping the string is a good solution, proper support would be better.
  • ideally I would phase out as many inputtext callbacks in favor of using input routing check + making it easier to externally access and edit input text contents.

So adding another layer of complexity into existing callbacks in order to facilitate developing a workaround for a feature seems like a patch over a patch. But if you can think of something simple I can do I'll try to help.

@inflex
Copy link
Author

inflex commented Apr 2, 2025

I appreciate the candid response. I agree a proper WW solution within InputTextMultiline would be the most ideal solution though I know you've got your plate more than full with everything else you're handling, so I'm taking this path as a "bodge" solution until such time that it arrives in native form.

I'll ponder on my options a little more and report back. Thank you again for your time.

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