ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.11k stars 10.3k forks source link

InputText CTRL+V paste fails if text is too long #7594

Open Infiziert90 opened 6 months ago

Infiziert90 commented 6 months ago

Version/Branch of Dear ImGui:

1.90.2 and before

Back-ends:

Win32 DirectX11

Compiler, OS:

MSVC, Windows 10

Full config/build information:

No response

Details:

Trying to paste a text with < 500 characters into a InputText(label, string, 500) will straight up fail, resulting in nothing be added.

The behaviour of other programs is more of a cut-off at exactly 500 letters, and i wanted to recreate this. Is it possible to achieve something similar with ImGui?

So:

Looked over the Callback events, there doesn't seem to be one handled through the InputText directly

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

ocornut commented 6 months ago

The behaviour of other programs is more of a cut-off at exactly 500 letters

I don't think many other programs have limitations? More often a real application would wrap InputText() to use std::string or their own string type, as shown e.g. https://github.com/ocornut/imgui/blob/master/misc/cpp/imgui_stdlib.h Are you sure you simply don't want to do that?

Or you want to actually benefit from the clamped pasting?

Infiziert90 commented 6 months ago

My case requires a hard limit of 500 characters, so for me clamping is the bigger benefit

User can still paste their text without the text box just staying blank the moment it goes above 500

ocornut commented 6 months ago

The ideal fix would requires reworking how calls to STB_TEXTEDIT_INSERTCHARS() are handled:

Another strategy which seems simpler if we perform a clamped call to stb_textedit_paste() directly in our handler, and only in the case where the buffer is not resizable.

ocornut commented 6 months ago

One thing that makes me uneasy about clamping the pasted contents is if you paste from beginning or middle of an existing thing, then your pasted content would be cut off but the cut off is likely to be less visible.