Minimal clipboard handling #95
Loading…
Reference in New Issue
No description provided.
Delete Branch "ilidemi/orca:minimal-clipboard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Handling the basic case of copy-pasting text with platform hotkeys without the need for permissions.
ctrl+v/cmd+v/shift+ins, runtime generates an extraOC_EVENT_CLIPBOARD_PASTEevent. Guest can call oc_clipboard_get_string() while in the event handler (but doesn't have to). Outside the event handler, the call is a no-op that emits a warning.ctrl+x/ctrl+c/..., runtime opens a 1 second window for the guest to calloc_clipboard_set_string(). After the window passes, the call is a no-op that emits a warning.The change introduces a bit of new organization, feedback and nitpicks are welcome.
The new
clipboardArenaseems very special case but we can't useframeArenabecause it gets reset atbegin_frame(), and clipboard text will likely come beforebegin_frame()and can be discarded atend_frame().The hotkeys are duplicated in
runtime_clipboard.candui.c- my understanding is that the only way to unify would be to have all of them as#defines (because commands inui.cneed to be constants) and that would be fairly ugly.The new API would probably need to be documented.
aea6543c7ctof0616ba27eWould also appreciate someone testing on a Mac.
A few nitpicks:
You should avoid directly using
oc_scratch()outside of the highest level runloops, since you can accidentally clear stuff pushed upstream (I think it can happen inoc_runtime_clipboard_process_event(), line 78 for example). Prefer usingoc_scratch_begin()/oc_scratch_end(). (I should probably removeoc_scratch()altogether)Is
oc_wasm_arena_push_addr()really necessary? We always calloc_wasm_address_to_ptrnext. However, it is a good call to check the length available to that pointer! But we could do that check inoc_wasm_arena_push()You can
#ifguard the wholeoc_ui_clipboard_register_default_hotkeys(and its declaration), so that using it would result in a compile-time error rather than a runtime oneDo we need pasted text in every box
ui_sigstruct? Couldn't we rather checkoc_clipboard_pasted_textwhen text box has focus?Maybe we could clear frameArena at the end of the frame and use it for clipboard stuff (avoiding a second clipboardArena)
Maybe we could avoid having to call
oc_ui_clipboard_register_default_hotkeys()by having a function to query the clipboard (that takes an arena) that is only enabled when processing a paste event. Registering different hotkeys also wouldn't need passing the ui context.Works on macOS btw!
All good feedback. On
frameArena, I got a wrong impression that boxes live there and need to survive till render, now I see there's a persistent pool.Changed the paste to generate an extra event so that the guest doesn't have to guess where did their keypresses go if they're not using the clipboard.
f92523d13ctoe057105586e057105586toa5567da82c