Repository navigation
fix(html): keep menu shortcuts working over a page that failed to load - #1176
pavel-alay wants to merge 1 commit into
Conversation
A page that failed before WebKit started its web content process (a restored file page whose file is gone, or a page whose process terminated) still took first responder when its session was selected. WebKit then claimed every key equivalent and dropped it, so the palette, session navigation and every other menu chord did nothing in that window; only close_session got through, via CustomCommandRunner. HtmlOverlayWebView.becomeFirstResponder now refuses while the page's model load state is failed, read live through the page because a restored page fails inside makeNSView, before any view update sees it. HtmlWebViewHost gives up focus when a focused page fails and takes it back once a reload loads.
umputun
left a comment
There was a problem hiding this comment.
the fix works for menu chords, but refusing focus on every failed page breaks the Esc close path.
agterm/Views/HtmlOverlayView.swift:234+agterm/Views/HtmlOverlayWebView.swift:69- a viewer (text, log, markdown, image, pdf) whose reload fails no longer closes on Esc or⌘., both just beep.onCancelneeds the web view to be first responder, and the page gives it up as soon as it fails. Repro: open a text file as a viewer, delete the file, reload, press Esc. On master it closes, assite/docs.htmlsays.- same lines - with the window itself as first responder, macOS 26 turns an unclaimed
⌘.intoNSWindow.cancelOperation:, which takes a full-screen window out of full screen (#753). I couldn't test it on 26, on 27 both keys only beep.
what the fix needs to keep true: menu chords reach the menu over a failed page, a failed viewer still closes on Esc and ⌘., and neither key reaches the window's cancelOperation:. One way that fits: keep the web view focusable (drop the becomeFirstResponder guard and the resign in updateNSView), return false from performKeyEquivalent while loadFailed is true so the menu gets the chord, and send Esc and an unclaimed ⌘. from keyDown straight to the existing cancelOperation/onCancel path, since WebKit drops key events when no web content process runs. Pls cover Esc and ⌘. on a failed viewer with no document, plus ⌘K reaching the menu.
two small ones:
- the
loadFaileddoc comment and the newcontrol-api.mdsentence say the same thing, keep it in one place and have the other point to it. - the
loadFailedclosure spells out the id-to-page lookup that already exists in a few places (e.g.AppStore.replicaPageState). Pls add oneagtermCorehelper next tohtmlOverlaySlotthat returns the page'sHtmlOverlayfor an id and use it here.
Problem
A page that fails to load can leave its window deaf to every menu shortcut. Repro: open a page whose file lives in a temp dir (
session overlay open --html $TMPDIR/x.html --companion), restart the Mac or delete the file, relaunch, select the page session. The panel shows "The page could not be loaded", and the command palette, Go to Session, next/previous session and the other menu chords do nothing in that window. Only ⌘W works.Cause
Selecting the session makes the failed page's
HtmlOverlayWebViewfirst responder. When the page failed before WebKit started its web content process (a file page without--cwdwhose file is gone fails inloadOriginalbefore any load), or after that process terminated, WKWebView still claims every key equivalent inperformKeyEquivalentand then drops it, because there is no process to send it to. ⌘W survives only becauseCustomCommandRunnermatchesclose_sessionwhile a page holds focus.Fix
HtmlOverlayWebView.becomeFirstResponderrefuses while the page's load state isfailed. It reads the model live throughHtmlOverlayPage(loadFailed): a restored page fails insidemakeNSView, soupdateNSViewstill holds theloadingvalue and no copy taken there would be current.becomeFirstResponderis the gate becauseNSWindow.makeFirstRespondernever asksacceptsFirstResponder.HtmlWebViewHost.updateNSViewgives up focus when a focused page fails, and re-arms so a reload that loads takes the keyboard back.The keys then go to the menu as in any window without a focused view. The hidden terminal under the page does not get them. A replica page on a viewing Mac goes through the same view and model, so the remote path needs nothing extra.
Tests
HtmlOverlayViewTests.testAFailedPageLeavesMenuChordsToTheMenuUntilAReloadLoadsIt: a restored page with a missing file refusesfocusCover, a ⌘K key equivalent is not swallowed, a reload takes focus back, and a web content process termination gives it up again. Fails on master (⌘K swallowed), passes here.make test-app(2752 tests) andmake lintpass.swift testhas one failure,RemoteSessionTests.controlReachesTheCliWithEveryArgumentIntactUnderAnyLoginShellwith/opt/homebrew/bin/fish; this change touches noagtermCorecode. Likely the local fish config, not confirmed.