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

Fix valid unicode in clipboard paste being filtered by special key filter #4005

Closed

Conversation

dougbinks
Copy link
Contributor

Note: This PR is based on docking branch, but I can create a master branch PR if required.

Currently pasting a valid unicode character (such as when using an icon font) can result in it being filtered by the lines:

    // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
    if (c >= 0xE000 && c <= 0xF8FF)
        return false;

Since pastes originate from the clipboard, they are likely valid unicode and do not originate from these special keys, thus my proposed solution is a flag which hints the data source is from a clipboard, rather than from key presses:

    // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME)
    if ( !(flags & ImGuiInputTextFlags_FromClipboard) && c >= 0xE000 && c <= 0xF8FF)
        return false;

This is a 3 line change (actually 4 since there is a separator needed on the last flag), with limited surface area. Since it's fairly simple it may be easiest for you to modify the code directly rather than accept this PR.

@ocornut
Copy link
Owner

ocornut commented Apr 6, 2021

Thank you Doug, this makes sense!

I'm tempted to avoid leaking this into flags since it really only applies to the helper InputTextFilterCharacter() function. My suggestion would be to add a ImGuiInputSource_Clipboard value in ImGuiInputSource and add the parameter to InputTextFilterCharacter().

I can apply this very easily, do you mind if I perform the change (and attribute the commit to you) or do you prefer doing it on your side?

@dougbinks
Copy link
Contributor Author

If it's easier for you to do then go ahead, if not let me know and I can handle it later on today. I'm not worried about attribution :)

ocornut pushed a commit that referenced this pull request Apr 6, 2021
@ocornut
Copy link
Owner

ocornut commented Apr 6, 2021

Reworked and merged (see f08566b), thank you!

@ocornut ocornut closed this Apr 6, 2021
@dougbinks
Copy link
Contributor Author

Thanks!

ocornut added a commit that referenced this pull request Apr 7, 2021
dougbinks added a commit to dougbinks/imgui that referenced this pull request Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants