Skip to content

core: Implement TextField control characters #2081

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

Closed

Conversation

JMcKiern
Copy link
Contributor

@JMcKiern JMcKiern commented Dec 24, 2020

This pr implements some control character handling for text fields (eg CtrlC, CtrlV).

I'm submitting this as a draft to make sure that I'm going about this the right way.

TODO

  • - Up, Down - Should move caret between lines
  • - Home, End - Should go to the start/end of the line
  • - Ctrl+Left, Ctrl+Right - Should go to the start/end of the previous/next word

@Herschel
Copy link
Member

Herschel commented Dec 27, 2020

I was thinking maybe we should add a separate enum to handle keyboard control/navigation commands, i.e. something like PlayerEvent::TextControl that would have MoveLeft, SelectAll, Copy, PageUp, etc., and this could be handled by a separate method on the textfield. This way these commands are explicit, as opposed to being dumped into the ASCII control characters (e.g. on Mac, where Cmd+C is different from Ctrl+C, Ctrl+Ins for copy on Windows).

@JMcKiern JMcKiern force-pushed the textfield-control-characters branch from f10dfad to f303c00 Compare January 17, 2021 20:28
@JMcKiern
Copy link
Contributor Author

Hey, sorry for the wait. I've added the TextControl event, a TextControlCode enum and implemented SelectAll, Copy, Paste and Cut.

I couldn't figure out how to check if Ruffle is running on MacOS on web so I've just left this as a TODO.

Also, should I move the following to this TextControl implementation?

  • Backspace and Delete - currently handled in text_input()
  • Left and Right - currently handled in handle_clip_event()

@Herschel
Copy link
Member

Yes, I'd say lets try to get all of the navigation and control commands into one code path.
For Copy/Paste on Web, I wonder if it should hook into https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event instead of explicitly looking for keys.

@JMcKiern
Copy link
Contributor Author

I've moved Delete and Backspace to text_control_input() but I just want to note here that I need to look into the onKeyDown and similar listeners. For example, it fires for Backspace but not for Ctrl+C.

For those copy events, it looks like we'd need to enable the unstable apis in web_sys: https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.ClipboardEvent.html

@Herschel
Copy link
Member

I think enabling the unstable APIs is fine (we are somewhat on the bleeding edge of things, so we can deal with APIs breaking from time to time).

@Txori
Copy link
Contributor

Txori commented Jul 14, 2022

Hello, you forgot to add Page Up and Page Down to the TODO list :)

@allancoding
Copy link

Is there any update on progress?

@n0samu
Copy link
Member

n0samu commented May 22, 2023

I updated and finished this PR in #11059. Thanks so much for your work on this!

@n0samu n0samu closed this May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants