Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions desktop/e2e/keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,23 @@ test("cycles: ⌃Tab and ⌥Tab commit once, on releasing the held modifier", as
await page.keyboard.down("Control");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await expect(cycleRow("tabs")).toHaveAttribute("data-cycle-row", tabs[2]!);
await expect(cycleRow("panels")).toHaveAttribute("data-cycle-row", tabs[2]!);
expect(sent.get("focus_tab") ?? 0).toBe(focused);
await page.keyboard.up("Control");
await expect(page.locator("[data-cycle]")).toHaveCount(0);
await expect(canvas).toHaveAttribute("data-canvas", tabs[2]!);
await exactlyOnce(sent, "focus_tab", focused + 1, page);

// ⌃⇧Tab walks backward: from third, one back past the end is second.
// ⌃⇧Tab walks back toward the start: from third, two forward then one
// back is first, the order Recent Panels holds across every checkout.
focused = sent.get("focus_tab") ?? 0;
await page.keyboard.down("Control");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Shift+Tab");
await expect(cycleRow("tabs")).toHaveAttribute("data-cycle-row", tabs[1]!);
await expect(cycleRow("panels")).toHaveAttribute("data-cycle-row", tabs[0]!);
await page.keyboard.up("Control");
await expect(canvas).toHaveAttribute("data-canvas", tabs[1]!);
await expect(canvas).toHaveAttribute("data-canvas", tabs[0]!);
await exactlyOnce(sent, "focus_tab", focused + 1, page);

// Recent Projects gamma, beta, fixture: fixture is current.
Expand All @@ -172,25 +175,26 @@ test("cycles: ⌃Tab and ⌥Tab commit once, on releasing the held modifier", as
await expect(checkout(name)).toHaveAttribute("aria-current", "true");
}

// ⌥Tab twice walks to gamma; releasing ⌥ commits one focus_checkout.
focused = sent.get("focus_checkout") ?? 0;
// ⌥Tab twice walks to gamma; releasing ⌥ commits one focus_tab, back on
// the tab gamma was last used on.
focused = sent.get("focus_tab") ?? 0;
await page.keyboard.down("Alt");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await expect(cycleRow("projects")).toBeVisible();
expect(sent.get("focus_checkout") ?? 0).toBe(focused);
expect(sent.get("focus_tab") ?? 0).toBe(focused);
await page.keyboard.up("Alt");
await expect(page.locator("[data-cycle]")).toHaveCount(0);
await expect(checkout("gamma")).toHaveAttribute("aria-current", "true");
await exactlyOnce(sent, "focus_checkout", focused + 1, page);
await exactlyOnce(sent, "focus_tab", focused + 1, page);

// ⌥⇧Tab walks backward: from gamma, one back past the end is beta.
focused = sent.get("focus_checkout") ?? 0;
focused = sent.get("focus_tab") ?? 0;
await page.keyboard.down("Alt");
await page.keyboard.press("Shift+Tab");
await page.keyboard.up("Alt");
await expect(checkout("beta")).toHaveAttribute("aria-current", "true");
await exactlyOnce(sent, "focus_checkout", focused + 1, page);
await exactlyOnce(sent, "focus_tab", focused + 1, page);
} finally {
for (const id of extraWorkspaces) herdr.run(["workspace", "close", id]);
for (const id of tabs.slice(1)) herdr.run(["tab", "close", id]);
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export const MENU_LAYOUT: Readonly<Record<"app" | "File" | "Edit" | "View" | "Pa
};

export const KEYBOARD_ONLY: readonly CommandId[] = [
"recent_tab",
"previous_recent_tab",
"recent_panel",
"previous_recent_panel",
"recent_project",
"previous_recent_project",
"move_to_trash",
Expand Down
7 changes: 4 additions & 3 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ The reconcile holds the display cap too: such a tab of a Workspace that already
With the regions separate, choosing an Agent tab no longer takes the editor off screen: `editor.active_tab_id` is the document of the active area's active display, null while that display is not open (`front_active_view_tab` in `runtime/view_areas.rs`, applied by the reconcile), where before every terminal choice deactivated it.
The core also owns when the hidden area comes back (D-08): an explicit file open, reveal or History selection from Agents only switches to Agents and Views, and an explicit agent or tab choice from Views only does the same; a status change, a hover or a menu opening moves nothing, and a refused event moves nothing either.
A device agent or tab chosen through `remote_control` brings the Agent area back on the Workspace that holds it, resolved from the device session in the same event, because the device's front moves only when its Herdr answers.
Choosing a Workspace or an agent on another device than the one in front is one event: `focus_checkout`, `focus_pane` and `remote_control` carry `focus_device`, and the core brings that device forward only when it accepts the request, so a refusal leaves the device in front where it was.
Choosing a Workspace or an agent on another device than the one in front is one event: `focus_checkout`, `focus_tab`, `focus_pane` and `remote_control` carry `focus_device`, and the core brings that device forward only when it accepts the request, so a refusal leaves the device in front where it was.
A Recent Panels commit of a display in another checkout is one `focus_checkout` naming it by `display_id`: the core checks the display is in that checkout's Workspace before moving anything, brings the checkout forward, shows its View area if only Agents showed, and makes the display the one in use; an unknown display refuses the whole event with `view_layout.unknown_display`.

The snapshot's `workspace_view.layout` is the front Workspace's tree with its `active_area`, `limits` and `display_count`, each display carrying its `tab_id`, `label`, `kind`, `committed`, `preview` and `state` with an optional `reason`; `editor.tabs` still lists every document.
A restored Workspace's tree, ratios, tab order, preview flags, active displays, active area, mode and tools are published the first time it is in front in a process, before any file is read, so the layout appears whole rather than tab by tab.
Expand Down Expand Up @@ -624,8 +625,8 @@ The e2e covers each path alone (a Playwright chord, a main-process menu click, o
| Close tab | ⌘W | ⌥W (moved) | ⌘W |
| Reopen closed tab | ⌘⇧T | ⌥⇧T (moved) | ⌘⇧T |
| New workspace | ⌘⇧N | ⌥⇧N (moved) | ⌘⇧N |
| Next / previous recent tab | ⌃Tab / ⌃⇧Tab | ⌥` / ⌥⇧` (moved) | ⌃Tab / ⌃⇧Tab, committed on releasing ⌃ |
| Next / previous recent project | ⌥Tab / ⌥⇧Tab | ⌥Tab / ⌥⇧Tab | ⌥Tab / ⌥⇧Tab |
| Next / previous recent panel (Recent Panels) | ⌃Tab / ⌃⇧Tab | ⌥` / ⌥⇧` (moved) | ⌃Tab / ⌃⇧Tab, committed on releasing ⌃ |
| Next / previous recent project (Recent Projects) | ⌥Tab / ⌥⇧Tab | ⌥Tab / ⌥⇧Tab | ⌥Tab / ⌥⇧Tab |
| Search, Open file, Toggle right panel | ⌘K, ⌘P, ⌘⇧B | same chords; ⌘K and ⌘P answered by the palettes | same chords |
| Project home | ⌘⇧H | same chord; opens the front checkout's Project Overview | same chord |
| Save file | ⌘S | ⌘S | ⌘S |
Expand Down
13 changes: 8 additions & 5 deletions docs/UI_BEHAVIOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ An add that lands mid-removal cancels the removal and says so, rather than losin

## Recent navigation

Native owner: `AgentMRU.swift`, `ShellModel.swift`, `ShellModelNavigation.swift`. Web owner: `web/src/recent.ts`.

Cycling recent surfaces walks every unified surface in recent-use order, across every project, checkout, and device the session holds: terminal, file/editor, and diff tabs.
The overlay ("Recent Panels") returns to the actually previous surface on a single chord, and repeated chords toggle between the last two surfaces; holding the modifier while repeating the chord walks older visits rather than tab-strip or agent-list order.
A second cycle scopes to projects globally and restores each project's last used surface.
Native owner: `AgentMRU.swift`, `ShellModel.swift`, `ShellModelNavigation.swift`. Web owner: `web/src/recent.ts`, `web/src/keyboard.ts`, and `CycleOverlay` in `web/src/Overlays.tsx`.

Cycling recent surfaces walks every unified surface in recent-use order, across every project, checkout, and device the session holds: terminal, file/editor, and diff tabs, and on the web every View-area display (file, diff, and browser).
The overlay ("Recent Panels", ⌃Tab / ⌃⇧Tab in the desktop app and the Swift app, ⌥` / ⌥⇧` in a browser, where Chrome keeps ⌃Tab) returns to the actually previous surface on a single chord, and repeated chords toggle between the last two surfaces; holding the modifier while repeating the chord walks older visits rather than tab-strip or agent-list order.
A second cycle ("Recent Projects", ⌥Tab / ⌥⇧Tab) scopes to projects globally and restores each project's last used surface.
Committing a row brings its surface forward in its own project and checkout, switching the Workspace when needed, as one event; a display's View area shows if only Agents showed, and the keyboard lands in it.
On the web a surface is in use where the keyboard is: the focused checkout's active display while the keyboard is in its View area (or only Views show), else its visible Herdr tab; a commit's intermediate frames are not visits.
The web shell's Recent Panels order holds this machine's surfaces only: a device's tab or display cannot be brought forward from another context in the web shell yet, so no row stands for one; while a device is in front, nothing of this machine's counts as in use, and Recent Panels walks that device's visible checkout's Herdr tabs, the shown one first.
Holding the chord's modifier previews; releasing it commits; Escape keeps the original selection; a menu action commits immediately.
Reopen Closed Tab is disabled when the session-local recent-close stack is empty or a restore is already running, and restoration works regardless of which surface currently owns focus.
Restoration is one action with no confirmation: an in-flight pane shows inline progress, and a restore without a target pane shows a compact inline warning.
Expand Down
38 changes: 37 additions & 1 deletion herdr-core/src/runtime/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,23 @@ pub(super) struct FocusCheckoutPayload {
/// accepted, as `FocusPaneRequestPayload::focus_device` does.
#[serde(default)]
pub(super) focus_device: bool,
/// The checkout comes forward on this View display rather than on its
/// Agent tab: its Workspace's View area shows and the display takes it,
/// in the same event (Recent navigation). A display the Workspace no
/// longer holds refuses the whole event, so nothing moves.
#[serde(default)]
pub(super) display_id: Option<String>,
}

#[derive(Debug, Deserialize)]
pub(super) struct FocusTabPayload {
pub(super) workspace_id: String,
pub(super) checkout_id: String,
pub(super) tab_id: String,
/// Also makes this machine the device in front when the tab is accepted,
/// as `FocusCheckoutPayload::focus_device` does.
#[serde(default)]
pub(super) focus_device: bool,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -1448,7 +1458,30 @@ impl Runtime {
true
}
Event::FocusCheckout(payload) => {
let changed = self.focus_checkout(&payload.workspace_id, &payload.checkout_id);
if let Some(display_id) = payload.display_id.as_deref()
&& let Err(error) = self.view_display_known(
&payload.workspace_id,
&payload.checkout_id,
display_id,
)
{
self.set_error(error.kind(), error.message(), false);
return true;
}
let mut changed = self.focus_checkout(&payload.workspace_id, &payload.checkout_id);
// The display follows whenever the checkout came forward: a
// later failure inside the checkout focus (a pane projection
// worker) must not leave the checkout moved without it.
if let Some(display_id) = payload.display_id.as_deref()
&& self.snapshot.navigator.focused_checkout_id.as_deref()
== Some(payload.checkout_id.as_str())
{
changed |= self.focus_view_display_of(
&payload.workspace_id,
&payload.checkout_id,
display_id,
);
}
if payload.focus_device
&& self.snapshot.status.last_error.is_none()
&& !self.device_in_front(workspace::LOCAL_DEVICE_ID)
Expand Down Expand Up @@ -1534,6 +1567,9 @@ impl Runtime {
self.refresh_pane_read_state();
self.yield_surface_to_terminal();
self.persist_current_ui_state();
if payload.focus_device && !self.device_in_front(workspace::LOCAL_DEVICE_ID) {
self.bring_device_forward(workspace::LOCAL_DEVICE_ID.to_owned());
}
// A first visit attaches the tab's panes now. Waiting for the
// next session update to do it left the canvas empty until
// Herdr happened to emit something, up to the catalog window.
Expand Down
78 changes: 78 additions & 0 deletions herdr-core/src/runtime/tests/view_areas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,3 +2195,81 @@ fn a_page_survives_a_restart_and_closes_like_any_view() {
assert!(browser_displays(&mut restarted).is_empty());
assert_eq!(labels(&mut restarted), vec![vec!["a.md"]]);
}

/// Recent navigation: a `focus_checkout` naming a display of another
/// Workspace brings that checkout forward on the display in one event, the
/// View area shown even when only Agents showed there; a display the
/// Workspace does not hold refuses the event and nothing moves.
#[test]
fn a_checkout_focus_naming_a_display_brings_it_forward_on_that_display() {
let (runtime, checkout_id, directory) = strip_checkout("view-focus-display");
let mut runtime = runtime;
let (other, other_checkout) = second_checkout(&mut runtime, &directory);
let mut runtime = with_views(runtime, &views_path("view-focus-display"));
files(&directory, &["a.md", "b.md"]);
open(
&mut runtime,
&checkout_id,
&directory.join("a.md"),
false,
false,
);
open(
&mut runtime,
&checkout_id,
&directory.join("b.md"),
false,
false,
);
let a = display(&mut runtime, 0, "a.md");
layout(&mut runtime, serde_json::json!({"mode": "agents"}));
runtime.dispatch_json(&explorer_event(
"focus_checkout",
serde_json::json!({"workspace_id": "workspace:other", "checkout_id": other_checkout}),
));
assert_eq!(runtime.snapshot.status.last_error, None);

runtime.dispatch_json(&explorer_event(
"focus_checkout",
serde_json::json!({"workspace_id": "workspace:order", "checkout_id": checkout_id, "display_id": "d-missing"}),
));
assert_eq!(
runtime
.snapshot
.status
.last_error
.as_ref()
.map(|error| error.kind.as_str()),
Some("view_layout.unknown_display")
);
assert_eq!(
runtime.snapshot.navigator.focused_checkout_id.as_deref(),
Some(other_checkout.as_str()),
"a refused display moves no checkout"
);

runtime.dispatch_json(&explorer_event(
"focus_checkout",
serde_json::json!({"workspace_id": "workspace:order", "checkout_id": checkout_id, "display_id": a}),
));
assert_eq!(runtime.snapshot.status.last_error, None);
assert_eq!(
runtime.snapshot.navigator.focused_checkout_id.as_deref(),
Some(checkout_id.as_str())
);
runtime.sync_workspace_view();
let view = runtime
.snapshot
.workspace_view
.clone()
.expect("a front Workspace");
assert_eq!(view.path, directory.to_string_lossy());
assert_eq!(
view.mode,
crate::workspace_views::ViewMode::Together,
"the View area shows again"
);
let (_, active, _) = areas(&view.layout).remove(0);
assert_eq!(active.as_deref(), Some(a.as_str()));
drop(other);
}
46 changes: 45 additions & 1 deletion herdr-core/src/runtime/view_areas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use serde::Deserialize;

use super::documents::OpenRequestFields;
use super::workspace_view::{WorkspaceKey, file_label};
use super::workspace_view::{AreaIntent, WorkspaceKey, file_label};
use super::*;
use crate::model::{
BrowserOpenReceiptSnapshot, ViewAreaSnapshot, ViewDisplaySnapshot, ViewDisplayState,
Expand Down Expand Up @@ -352,6 +352,50 @@ impl Runtime {
.map(|view| &view.layout)
}

/// Whether the Workspace of a checkout holds `display_id`, before a
/// `focus_checkout` that names it moves anything.
pub(super) fn view_display_known(
&self,
workspace_id: &str,
checkout_id: &str,
display_id: &str,
) -> Result<(), LayoutError> {
if !self.separate_view_areas() {
return Err(LayoutError::UnknownDisplay(display_id.to_owned()));
}
self.workspace_key(workspace_id, checkout_id)
.and_then(|key| self.view_layout_of(&key))
.and_then(|layout| layout.display(display_id))
.map(|_| ())
.ok_or_else(|| LayoutError::UnknownDisplay(display_id.to_owned()))
}

/// A display of the checkout just brought forward takes its View area,
/// shown with the Agent area if only Agents showed (D-08). Returns
/// whether the layout changed.
pub(super) fn focus_view_display_of(
&mut self,
workspace_id: &str,
checkout_id: &str,
display_id: &str,
) -> bool {
let Some(key) = self.workspace_key(workspace_id, checkout_id) else {
return false;
};
self.apply_area_intent_to(&key, AreaIntent::Views);
match self.change_view_layout(&key, |layout, stamp| {
layout
.focus(display_id, stamp)
.map(|changed| (changed, changed))
}) {
Ok(changed) => changed,
Err(error) => {
self.set_error(error.kind(), error.message(), false);
true
}
}
}

/// Applies one change to a Workspace's layout, created when the file has
/// none for it, and saves it when it changed something.
fn change_view_layout<T>(
Expand Down
Loading
Loading