From be7328c8eb1d67a64d08cddd14548df4627b24de Mon Sep 17 00:00:00 2001 From: Codeman maintainer Date: Wed, 7 Oct 2026 03:45:07 +0200 Subject: [PATCH] refactor(tiles): the picker's Open and "Open group as tiles" share _replaceTileGrid Both put a new set of sessions on the grid in place of the open one: choose the focus (the session in focus if the set holds it, else the first), close an open grid forgotten, drop activeSessionId so re-parking snapshots nothing, then open. They now call one _replaceTileGrid(ids), which carries the reason for the order once. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/web/public/tile-grid.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/web/public/tile-grid.js b/src/web/public/tile-grid.js index fd4ac15e..978a2170 100644 --- a/src/web/public/tile-grid.js +++ b/src/web/public/tile-grid.js @@ -449,16 +449,7 @@ Object.assign(CodemanApp.prototype, { open.addEventListener('click', () => { const ids = boxes.filter((b) => b.checked).map((b) => b.value); this.closeTilePicker(); - if (ids.length === 0) return; - const focus = ids.includes(this.activeSessionId) ? this.activeSessionId : ids[0]; - if (this._tilesOwnTerminal()) { - // A new set for the open grid, as "Open group as tiles" does it: the - // parked terminal still holds what it showed before the grid, and - // re-parking must not snapshot it. - this.closeTileGrid({ keepStored: false, reselect: false }); - this.activeSessionId = null; - } - this.openTileGrid(ids, { focusedId: focus }); + if (ids.length > 0) this._replaceTileGrid(ids); }); document.body.appendChild(menu); @@ -879,13 +870,23 @@ Object.assign(CodemanApp.prototype, { this.showToast?.('This group has no session to show as tiles', 'info'); return false; } - // Before the open grid closes (which drops activeSessionId): the session in - // focus keeps it if the group holds it, as with the picker's Open. + return this._replaceTileGrid(ids); + }, + + /** + * Opens the grid on `ids` in place of whatever it shows (the picker's Open, + * "Open group as tiles"): the session in focus keeps focus when `ids` holds + * it, otherwise the first one takes it. Chosen BEFORE an open grid closes, + * because the close drops activeSessionId: as in selectSession's tile + * branch, the parked terminal still holds what it showed before the grid, + * and re-parking must not snapshot it. + * + * @returns {boolean} whether the grid is open afterwards + */ + _replaceTileGrid(ids) { const focus = ids.includes(this.activeSessionId) ? this.activeSessionId : ids[0]; if (this._tilesOwnTerminal()) { this.closeTileGrid({ keepStored: false, reselect: false }); - // As selectSession's tile branch: the parked terminal still holds what it - // showed before the grid, and re-parking must not snapshot it. this.activeSessionId = null; } return this.openTileGrid(ids, { focusedId: focus });