Skip to content

Commit 4b165a0

Browse files
committed
fix(shell): keep new windows visible after creation
Creating a new workspace window should immediately scroll the active viewport enough to keep the newly focused window on-screen, matching the existing visible-window behavior used by shortcut-driven window moves. Constraint: The fix should apply to all create-window entry points, not just one toolbar button Rejected: Patch only the Dioxus button callback | other create-window callers would still leave focused windows off-screen Confidence: high Scope-risk: narrow Directive: Any action that focuses a different workspace window should consider viewport correction before returning
1 parent bd4b7d5 commit 4b165a0

1 file changed

Lines changed: 70 additions & 2 deletions

File tree

  • crates/taskers-shell-core/src

crates/taskers-shell-core/src/lib.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,10 +3549,14 @@ impl TaskersCore {
35493549
let Some(workspace_id) = model.active_workspace_id() else {
35503550
return false;
35513551
};
3552-
self.dispatch_control(ControlCommand::CreateWorkspaceWindow {
3552+
let changed = self.dispatch_control(ControlCommand::CreateWorkspaceWindow {
35533553
workspace_id,
35543554
direction: direction.to_domain(),
3555-
})
3555+
});
3556+
if changed {
3557+
return self.ensure_active_window_visible() || changed;
3558+
}
3559+
false
35563560
}
35573561

35583562
fn focus_workspace_window(&mut self, window_id: WorkspaceWindowId) -> bool {
@@ -9171,12 +9175,29 @@ mod tests {
91719175
#[test]
91729176
fn horizontal_scroll_host_events_pan_workspace_outside_overview() {
91739177
let core = SharedCore::bootstrap(bootstrap());
9178+
core.set_window_size(PixelSize::new(1280, 900));
91749179
core.dispatch_shell_action(ShellAction::CreateWorkspaceWindow {
91759180
direction: WorkspaceDirection::Right,
91769181
});
91779182
core.dispatch_shell_action(ShellAction::CreateWorkspaceWindow {
91789183
direction: WorkspaceDirection::Right,
91799184
});
9185+
let workspace_id = core.snapshot().current_workspace.id;
9186+
let widths = core
9187+
.snapshot()
9188+
.current_workspace
9189+
.columns
9190+
.iter()
9191+
.map(|column| (column.id, 720))
9192+
.collect::<Vec<_>>();
9193+
core.dispatch_shell_action(ShellAction::PreviewResize {
9194+
preview: ResizePreview::WorkspaceColumnWidths {
9195+
workspace_id,
9196+
widths,
9197+
},
9198+
});
9199+
core.dispatch_shell_action(ShellAction::CommitResizePreview);
9200+
core.dispatch_shell_action(ShellAction::ScrollViewport { dx: -50_000, dy: 0 });
91809201
let before = core.snapshot().current_workspace.viewport_x;
91819202

91829203
core.apply_host_event(HostEvent::ViewportScrolled { dx: 180, dy: 0 });
@@ -9190,6 +9211,53 @@ mod tests {
91909211
assert_eq!(overview_snapshot.current_workspace.viewport_x, after);
91919212
}
91929213

9214+
#[test]
9215+
fn creating_workspace_window_scrolls_new_active_window_into_view() {
9216+
let core = SharedCore::bootstrap(bootstrap());
9217+
core.set_window_size(PixelSize::new(1280, 900));
9218+
core.dispatch_shell_action(ShellAction::CreateWorkspaceWindow {
9219+
direction: WorkspaceDirection::Right,
9220+
});
9221+
9222+
let before = core.snapshot();
9223+
let workspace_id = before.current_workspace.id;
9224+
let widths = before
9225+
.current_workspace
9226+
.columns
9227+
.iter()
9228+
.map(|column| (column.id, 720))
9229+
.collect::<Vec<_>>();
9230+
core.dispatch_shell_action(ShellAction::PreviewResize {
9231+
preview: ResizePreview::WorkspaceColumnWidths {
9232+
workspace_id,
9233+
widths,
9234+
},
9235+
});
9236+
core.dispatch_shell_action(ShellAction::CommitResizePreview);
9237+
9238+
core.dispatch_shell_action(ShellAction::CreateWorkspaceWindow {
9239+
direction: WorkspaceDirection::Right,
9240+
});
9241+
9242+
let snapshot = core.snapshot();
9243+
let active_window = window_snapshot(&snapshot, snapshot.current_workspace.active_window_id);
9244+
let visible_left = snapshot.current_workspace.viewport_x;
9245+
let visible_right = visible_left + snapshot.portal.content.width;
9246+
9247+
assert!(
9248+
snapshot.current_workspace.viewport_x > 0,
9249+
"expected viewport to scroll toward the newly focused window"
9250+
);
9251+
assert!(
9252+
active_window.frame.x >= visible_left,
9253+
"expected active window left edge to be visible"
9254+
);
9255+
assert!(
9256+
active_window.frame.right() <= visible_right,
9257+
"expected active window right edge to be visible"
9258+
);
9259+
}
9260+
91939261
#[test]
91949262
fn browser_address_bar_normalizes_search_queries() {
91959263
assert_eq!(resolved_browser_uri(""), "about:blank");

0 commit comments

Comments
 (0)