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

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

Open
Infiziert90 opened this issue May 16, 2024 · 4 comments
Open

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

Infiziert90 opened this issue May 16, 2024 · 4 comments

Comments

@Infiziert90
Copy link

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:

  • User tries to paste
  • Check text for length
  • Cut if above X
  • Paste into the actual InputText

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 ocornut changed the title [Question] InputText CTRL+V paste fails if text is too long InputText CTRL+V paste fails if text is too long May 16, 2024
@ocornut
Copy link
Owner

ocornut commented May 16, 2024

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

Infiziert90 commented May 16, 2024

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

ocornut commented May 16, 2024

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

  • main meaningful one in stb_textedit_paste_internal() in imstb_textedit.h.
  • one in stb_textedit_replace() in imgui_widgets.cpp which is in theory cannot fail in normal condition (it would fail if user change underlying static buffer between activation and revert).
    But it probably means breaking stb_textedit.h API.

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

ocornut commented May 16, 2024

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.

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