diff --git a/changelog.d/1598-f-collapses-data-layers.md b/changelog.d/1598-f-collapses-data-layers.md new file mode 100644 index 0000000000..42bdc9d833 --- /dev/null +++ b/changelog.d/1598-f-collapses-data-layers.md @@ -0,0 +1,7 @@ +- `F` now collapses and reopens the Data Layers panel the way the panel's own + button does, and its rail entry stays. Before, `F` hid the panel together + with its rail entry, so only another `F` brought it back. When `F` or a + panel's collapse button hides a panel that holds the focus, including one + the opened panel folds away, the focus moves to that panel's rail entry; + in Cockpit, focus in the Contact card it folds moves to the card's expand + button (asturksever, #1598). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 809ceb47e0..51dd971fe0 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3350,7 +3350,10 @@ Browser acceptance: `QA_BASE_URL=http://127.0.0.1:4173 node scripts/qa-segmented `ui/input` supplies the bubbling application shortcut listener and generated shader-parameter rows. Number/style keys, H/O/V/F/D/C actions, native form-control -typing and Escape behavior retain their existing mappings. A shortcut key held +typing and Escape behavior retain their existing mappings. `F` collapses and +reopens Data Layers the way the panel's own collapse button does, so its rail +entry stays; if focus was inside the panel, it moves to that rail entry. +A shortcut key held with Cmd, Ctrl or Alt runs no shortcut, so the browser's own chord (Cmd+C to copy, Cmd+F to find, Cmd+1 to switch tab) does not also toggle CCTV, the layers panel or a style; Shift does not count, and Escape dismisses search either way. diff --git a/src/mapSourceFocus.test.mjs b/src/mapSourceFocus.test.mjs index 22d00f2cf8..a3b24ba23d 100644 --- a/src/mapSourceFocus.test.mjs +++ b/src/mapSourceFocus.test.mjs @@ -110,7 +110,7 @@ function harness({ hidden = false, selected = true, noChips = false } = {}) { window.performance = { now: () => now }; document.defaultView = window; const methods = new Function('createHoverDisclosure', 'collapsePanelOnEscape', 'document', 'window', 'clearTimeout', 'performance', 'requestAnimationFrame', 't', 'msg', 'readPanelState', - `return ({${shellMethod('_initAutoHoverPanel').toString()},\n${shellMethod('_collapsePanelOnEscape').toString()},\n${shellMethod('setPanelCollapsed').toString()},\n${shellMethod('_presentPanel').toString()},\n${shellMethod('_shownPanel').toString()}});`)( + `return ({${shellMethod('_initAutoHoverPanel').toString()},\n${shellMethod('_collapsePanelOnEscape').toString()},\n${shellMethod('_railFocusStand').toString()},\n${shellMethod('setPanelCollapsed').toString()},\n${shellMethod('_presentPanel').toString()},\n${shellMethod('_shownPanel').toString()}});`)( createHoverDisclosure, collapsePanelOnEscape, document, window, (id) => timers.delete(id), { now: () => now }, () => {}, t, msg, readPanelState, ); const saves = []; diff --git a/src/panelEscape.test.mjs b/src/panelEscape.test.mjs index 1177804d01..b3937beb94 100644 --- a/src/panelEscape.test.mjs +++ b/src/panelEscape.test.mjs @@ -42,7 +42,7 @@ function panelFixture({ id = 'data-panel', nested = false, nestedCollapsed = fal disclosure.closest = () => panel; } const document = { getElementById: (candidate) => candidate === id ? panel : null }; - const manager = new Function('document', 'getComputedStyle', 'collapsePanelOnEscape', `return {${method('_collapsePanelOnEscape', '_togglePanel')}};`)(document, (el) => ({ visibility: el.visibility ?? 'visible' }), collapsePanelOnEscape); + const manager = new Function('document', 'getComputedStyle', 'collapsePanelOnEscape', `return {${method('_collapsePanelOnEscape', '_togglePanel')}, ${method('_railFocusStand', '_setCommandDockPanelPinState')}};`)(document, (el) => ({ visibility: el.visibility ?? 'visible' }), collapsePanelOnEscape); manager.setPanelCollapsed = (candidate, value, options) => { assert.equal(candidate, id); assert.equal(value, true); diff --git a/src/ui/applicationShell.js b/src/ui/applicationShell.js index 59f4599d6b..cf270e6c47 100644 --- a/src/ui/applicationShell.js +++ b/src/ui/applicationShell.js @@ -637,6 +637,7 @@ export class StyleManager extends ShellFacade { _toggleOrbit: (...args) => this._toggleOrbit(...args), toggleCleanView: (...args) => this.toggleCleanView(...args), _toggleCctvEnabled: (...args) => this._toggleCctvEnabled(...args), + _togglePanel: (panelId) => this._panelChrome._togglePanel(panelId), _setBloomEnabled: (...args) => this._setBloomEnabled(...args), _setBloomIntensity: (...args) => this._setBloomIntensity(...args), _setSharpenEnabled: (...args) => this._setSharpenEnabled(...args), diff --git a/src/ui/displayBindings.js b/src/ui/displayBindings.js index 6aa2af9eea..401450222e 100644 --- a/src/ui/displayBindings.js +++ b/src/ui/displayBindings.js @@ -64,8 +64,8 @@ export class DisplayBindings { }, toggleOrbit: () => this._toggleOrbit(), toggleCleanView: () => this.toggleCleanView(), - toggleLayers: () => - document.getElementById('data-panel').classList.toggle('active'), + // Same collapse as the panel's own button, so its rail entry stays. + toggleLayers: () => this._togglePanel('data-panel'), cycleDetection: () => { this.shareLinkManager?.claimRestoreLane?.('visual'); this.claimDetection(); diff --git a/src/ui/panelChrome.js b/src/ui/panelChrome.js index 417d1e7658..6e71eaee70 100644 --- a/src/ui/panelChrome.js +++ b/src/ui/panelChrome.js @@ -205,22 +205,7 @@ export class PanelChrome { beforeCollapse: () => { if (panelId === 'location-bar') this._closeLocationSearch?.(); }, - // A desktop side panel hides entirely once collapsed; its rail item - // takes the focus its own disclosure can no longer hold. - returnFocusTo: () => { - const panel = document.getElementById(panelId); - if (!panel?.getClientRects || panel.getClientRects().length > 0) - return null; - const item = document.querySelector?.( - `.ui-rail [data-rail-item="${panelId}"]`, - ); - return item && - !item.disabled && - item.getClientRects().length > 0 && - getComputedStyle(item).visibility === 'visible' - ? item - : null; - }, + returnFocusTo: () => this._railFocusStand(panelId), }); } @@ -229,9 +214,49 @@ export class PanelChrome { if (this._disposed || !this._disclosurePanelIds?.has(panelId)) return; const panel = document.getElementById(panelId); if (!panel) return; + // Opening a panel folds others too (the side accordion, Cockpit's + // Contact card): note which open ones hold the focus. + const focused = document.activeElement; + const holders = [...this._disclosurePanelIds] + .map((id) => document.getElementById(id)) + .filter((el) => el?.contains(focused) && !this._shownPanel(el).collapsed); + const cockpit = this.cockpitView; + const contactHeld = + cockpit?.active && + !cockpit.contextCollapsed && + document.getElementById('cockpit-context')?.contains(focused); this.setPanelCollapsed(panelId, !this._shownPanel(panel).collapsed, { explicit: true, }); + const stand = + contactHeld && cockpit.contextCollapsed + ? document.getElementById('cockpit-context-toggle') + : holders + .filter((el) => this._shownPanel(el).collapsed) + .map((el) => this._railFocusStand(el.id)) + .find(Boolean); + stand?.focus({ preventScroll: true }); + } + + /** + * A desktop side panel hides entirely once collapsed; its rail item takes + * the focus its own disclosure can no longer hold. Null while the panel or + * the item is not shown. + * @param {string} panelId Panel element id. + */ + _railFocusStand(panelId) { + const panel = document.getElementById(panelId); + if (!panel?.getClientRects || panel.getClientRects().length > 0) + return null; + const item = document.querySelector?.( + `.ui-rail [data-rail-item="${panelId}"]`, + ); + return item && + !item.disabled && + item.getClientRects().length > 0 && + getComputedStyle(item).visibility === 'visible' + ? item + : null; } _setCommandDockPanelPinState( diff --git a/src/ui/panelChromeButtons.test.mjs b/src/ui/panelChromeButtons.test.mjs index eaada11a06..df83113b09 100644 --- a/src/ui/panelChromeButtons.test.mjs +++ b/src/ui/panelChromeButtons.test.mjs @@ -14,6 +14,8 @@ import PanelCollapseButton from './rail/PanelCollapseButton.vue'; import RailPanel from './rail/RailPanel.vue'; import UiPanel from './kit/UiPanel.vue'; import { usePanelChromeStore } from './stores/panelChrome.js'; +import { useDisplayStore } from './stores/display.js'; +import { DisplayBindings } from './displayBindings.js'; import CommandDockView from './views/CommandDockView.vue'; function mount(t, component) { @@ -487,3 +489,164 @@ test('the accordion closes peers through the real store, and opens them again', assert.equal(panels[0].className, ''); chrome.destroy(); }); + +test('F collapses Data Layers like its button and keeps its rail entry', (t) => { + document.body.innerHTML = ` + +
`; + const panel = document.getElementById('data-panel'); + const item = document.querySelector('[data-rail-item="data-panel"]'); + panel.getClientRects = () => + panel.classList.contains('collapsed') ? [] : [{}]; + item.getClientRects = () => [{}]; + const store = usePanelChromeStore(createPinia()); + const chrome = panelChrome(store); + followPanelState(store, 'data-panel', panel); + chrome._disclosurePanelIds = new Set(['data-panel']); + const bindings = new DisplayBindings({ + viewer: null, + services: { isScopeMaskEnabled: () => false, cycleDetectionMode() {} }, + elements: { _locationSearch: document.createElement('input') }, + operations: { + _setScope() {}, + _togglePanel: (panelId) => chrome._togglePanel(panelId), + }, + readState: () => ({}), + claimDetection() {}, + displayStore: useDisplayStore(createPinia()), + }); + bindings._initUI(); + t.after(() => { + bindings.destroy(); + chrome.destroy(); + }); + const press = (init = {}) => + document.activeElement.dispatchEvent( + new KeyboardEvent('keydown', { key: 'f', bubbles: true, ...init }), + ); + + panel.querySelector('button').focus(); + press(); + assert.equal(store.panels['data-panel']?.collapsed, true); + assert.ok(document.activeElement === item, 'focus moves to the rail'); + assert.ok(panel.classList.contains('collapsed')); + // `active` is what shows Data Layers at all (layers.css). + assert.ok(panel.classList.contains('active')); + press({ metaKey: true }); + assert.equal(store.panels['data-panel'].collapsed, true, 'Cmd+F is not ours'); + press(); + assert.equal(store.panels['data-panel'].collapsed, false); + assert.ok(!panel.classList.contains('collapsed')); + assert.ok(panel.classList.contains('active')); +}); + +test('F that folds a focused peer hands the focus to a rail entry', (t) => { + document.body.innerHTML = ` + +