feat(effects): add fx.focusView so a pure update can move view focus - #218
Open
sonhyrd wants to merge 1 commit into
Open
feat(effects): add fx.focusView so a pure update can move view focus#218sonhyrd wants to merge 1 commit into
sonhyrd wants to merge 1 commit into
Conversation
|
@sondh0127 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
`Runtime.focusView` and the `native-sdk.view.focus` bridge command both ship, but the effects channel had no focus verb — so a native-rendered app's `update`, which never sees the Runtime, could not move focus between its own views at all. That is load-bearing for a shell whose window holds a canvas beside a `<terminal>` and a WebView: AppKit's key-view loop does not span them (nothing in `appkit_host.m` wires `nextKeyView`, and `insertTab:` synthesizes a tab KEY into the canvas ring instead of calling `selectNextKeyView:`), and a focused terminal correctly keeps Tab for its child. Such an app has to own pane cycling on its own chord, and `Runtime.focusView` is exactly the primitive for it. Adds `focus_view_fn` to `WindowActionBinding`, `focusView` to `Effects(Msg)` beside the other window verbs, and `focus_view_count` / `lastViewLabel()` to the `WindowActionState` mirror — the window label rides `lastLabel()` with every other verb's, so the two together are the whole request. Refusals stay where they already live: `Runtime.focusView` reports unknown-view and unfocusable-view as errors, and the fire-and-forget contract turns them into no-ops.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
fx.focusView(window_label, view_label)— the effects-channel route toRuntime.focusView, which a pureupdatecannot reach.What was already there
Everything except the effect. The runtime method is complete and the bridge already exposes it; only the Zig app-facing verb was missing.
Runtime.focusView(window_id, label)src/runtime/window_view_runtime.zig:161native-sdk.view.focusbridge commandsrc/runtime/builtin_bridge.zig:322(focusViewFromJson)PlatformServices.focus_view_fnsrc/platform/types.zig:2360, implemented on the null platform and the hostsWindowActionBindingdeferral patternsrc/runtime/effects.zig—closeWindow(:7757),minimizeWindow,showWindow,quitAppSo a page can move focus through the bridge, and a Zig
updatecannot move it at all.Why this matters
Consider the layout the SDK now supports directly: a canvas, one or more
<terminal>elements, and a WebView in one window. Keyboard focus does not reach across those panes any other way:appkit_host.m— nonextKeyView, norecalculateKeyViewLoop, noinitialFirstResponder— anddoCommandBySelector'sinsertTab:(:7032) synthesizes atabkey into the canvas widget ring instead of callingselectNextKeyView:. Measured on that layout: eight Tab presses from a canvas text field walk six canvas widgets and produce zero page events.<terminal>is a Tab trap — correctly, since Tab belongs to the shell running in the pty.So an app with this layout has to own pane cycling on its own chord.
Runtime.focusViewis exactly the primitive for it; it just was not spendable fromupdate.Shape
Follows the four window verbs exactly — fire-and-forget, deferred through
WindowActionBinding, mirrored for hermetic tests:focus_view_fnonWindowActionBinding;effectsFocusViewByLabelinui_app.zigresolves the window label and callsRuntime.focusView.Runtime.focusViewreports unknown-view and unfocusable-view as errors, and the fire-and-forget contract turns them into no-ops — same contractcloseWindowdocuments for an unknown label.WindowActionStategrowsfocus_view_countandlastViewLabel(). The window label rideslastLabel()with every other verb's, so the two together are the whole request.Scope
focusNextView/focusPreviousViewwould follow the same shape if you want the trio; the by-label one is what the pane-cycling case needs, and the rest seemed better left to you.fx.focusView(label)resolving against the primary window would serve a single-window app fine.Cmdcounterpart is a separate decision.Verification
zig build test: no new failures (this checkout has 6 pre-existingfailed commandlanes locally — codesign identity, packaging fixtures — identical before and after).desktop-ui-shell-testslane run directly: 151/151 pass (150 before, plus the new one).zig fmt --checkclean.Tests
fx.focusView moves keyboard focus between views from a pure update(src/runtime/ui_app_window_tests.zig) — mounts a secondgpu_surfaceview beside the app canvas, dispatches a Msg whoseupdatecallsfx.focusView, and asserts the view took focus, the canvas lost it, and the mirror carries both labels. Then dispatches against an unknown view label and asserts the focus did not move and nothing crashed, while the mirror still counts the request.