diff --git a/src/web/src/grid-layout.js b/src/web/src/grid-layout.js index 28e4ffb1988..7bb3bf22735 100644 --- a/src/web/src/grid-layout.js +++ b/src/web/src/grid-layout.js @@ -4,6 +4,9 @@ import { LitElement, html, css, svg, nothing } from 'lit'; import { when } from 'lit/directives/when.js'; import { ifDefined } from 'lit/directives/if-defined.js'; +import { classMap } from 'lit/directives/class-map.js'; +import { createRef, ref } from 'lit/directives/ref.js'; +import { wheelDeltaPx } from './ui-utils.js'; // ─── Native CSS Grid IDE Layout Manager & Custom Elements ──────────────────── @@ -51,6 +54,24 @@ export function emitEvent(host, type, detail = {}) { })); } +// A tab icon's box, shared by the tab strip and the overflow menu. +const tabIconStyles = css` + .ide-tab-icon { + display: inline-flex; + align-items: center; + justify-content: center; + flex: none; + width: 13px; + height: 13px; + } + + .ide-tab-icon svg { + width: 100%; + height: 100%; + display: block; + } +`; + /** * - Encapsulated IDE window pane custom element using Lit. * Manages its header (tab bar and action controls) and content viewport. @@ -62,9 +83,12 @@ export class IdePaneElement extends LitElement { collapsible: { type: Boolean, reflect: true }, maximized: { type: Boolean, reflect: true }, collapsed: { type: Boolean, reflect: true }, + _menuOpen: { state: true }, + // Index, among the listed tabs, of the menu item with keyboard focus. + _focusIndex: { state: true }, }; - static styles = css` + static styles = [tabIconStyles, css` :host { display: flex; flex-direction: column; @@ -95,12 +119,21 @@ export class IdePaneElement extends LitElement { flex-shrink: 0; } + /* Fills up to the controls, so the fixed right-edge fade lies over + empty space when the tabs fit; a tab scrolled into view clears it, + and the end padding lets the last tab scroll clear of it too. */ .ide-tabs { display: flex; + flex: 1; height: 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; + padding-inline-end: 24px; + box-sizing: border-box; + scroll-padding-inline-end: 24px; + -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); + mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); } .ide-tabs::-webkit-scrollbar { @@ -130,22 +163,98 @@ export class IdePaneElement extends LitElement { transition: background-color 120ms ease, color 120ms ease; } - .ide-btn:hover { + .ide-btn:hover, + .ide-btn-tab-menu[aria-expanded="true"] { background: var(--bg-hover); color: var(--fg-primary); } + .ide-btn.ide-btn-restore { + width: auto; + padding: 0 6px; + border: 1px solid var(--border-strong); + color: var(--fg-primary); + } + + .ide-btn.ide-btn-restore:hover { + color: var(--accent); + border-color: var(--accent); + } + .ide-content { flex: 1; position: relative; overflow: hidden; } - `; + + /* Above Leaflet's controls (z-index 1000), below .context-menu. */ + .ide-tab-menu { + position: absolute; + top: 28px; + right: 4px; + z-index: 1100; + display: flex; + flex-direction: column; + min-width: min(160px, 100% - 8px); + max-width: calc(100% - 8px); + max-height: calc(100% - 32px); + overflow-y: auto; + padding: 4px 0; + background: var(--bg-context); + border: 1px solid var(--border-strong); + border-radius: var(--radius-sm); + box-shadow: 0 2px 8px var(--shadow); + box-sizing: border-box; + } + + .ide-tab-menu-item { + display: flex; + align-items: center; + gap: var(--space-sm, 6px); + padding: 5px 12px 5px 6px; + background: transparent; + border: none; + color: var(--fg-primary); + font-family: var(--font-sans); + font-size: var(--fs-12); + text-align: left; + white-space: nowrap; + cursor: pointer; + } + + .ide-tab-menu-item:hover, + .ide-tab-menu-item:focus-visible { + background: var(--bg-hover); + color: var(--fg-bright); + outline: none; + } + + .ide-tab-menu-item[aria-checked="true"] { + color: var(--accent-tab); + } + + .ide-tab-menu-check { + flex: none; + width: 12px; + text-align: center; + } + + .ide-tab-menu-title { + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + } + `]; constructor() { super(); - this._onMaximizeClick = this._onMaximizeClick.bind(this); - this._onCollapseClick = this._onCollapseClick.bind(this); + this._menuOpen = false; + this._focusIndex = 0; + this._slotRef = createRef(); + this._menuRef = createRef(); + this._btnRef = createRef(); + this._menuAbort = null; } connectedCallback() { @@ -153,6 +262,152 @@ export class IdePaneElement extends LitElement { this.classList.add('ide-pane', `ide-pane-${this.paneName}`); } + disconnectedCallback() { + super.disconnectedCallback(); + this._closeMenu(); + } + + willUpdate(changedProperties) { + if (!this._menuOpen) return; + // An empty menu has nothing to pick; its ▼ is disabled. + if (this._menuTabs.length === 0) { + this._closeMenu(); + return; + } + if (this.collapsed || changedProperties.has('maximized')) { + this._closeMenu(this._menuRef.value?.contains(this.renderRoot.activeElement)); + return; + } + // A listed tab may have been closed while the menu is open. + this._focusIndex = Math.min(this._focusIndex, Math.max(0, this._menuTabs.length - 1)); + } + + updated() { + if (this._menuOpen) this._menuRef.value?.children[this._focusIndex]?.focus(); + } + + get _tabs() { + return this._slotRef.value?.assignedElements() ?? []; + } + + get _menuTabs() { + return this._tabs.filter(tab => !tab.hidden); + } + + _onTabsWheel(e) { + const strip = e.currentTarget; + // Ctrl+wheel and trackpad pinch zoom the page. + if (e.ctrlKey || strip.scrollWidth <= strip.clientWidth + || Math.abs(e.deltaX) >= Math.abs(e.deltaY)) return; + e.preventDefault(); + // The vertical delta scrolls sideways, so a page is the strip's width. + strip.scrollLeft += wheelDeltaPx(e, () => strip.clientWidth)[1]; + } + + _onMenuButtonClick() { + if (this._menuOpen) { + this._closeMenu(true); + } else { + this._openMenu(); + } + } + + _openMenu() { + this._menuOpen = true; + this._focusIndex = Math.max(0, this._menuTabs.findIndex(tab => tab.active)); + this._menuAbort = new AbortController(); + const { signal } = this._menuAbort; + + document.addEventListener('pointerdown', (e) => { + const path = e.composedPath(); + if (!path.includes(this._menuRef.value) && !path.includes(this._btnRef.value)) { + this._closeMenu(); + } + }, { signal }); + + // Window capture: main.js reads Escape and single letters as shortcuts + // in document capture, which runs before any listener on the menu. + window.addEventListener('keydown', (e) => this._onMenuKey(e), { capture: true, signal }); + } + + _closeMenu(restoreFocus = false) { + this._menuAbort?.abort(); + this._menuAbort = null; + this._menuOpen = false; + if (restoreFocus) this._btnRef.value?.focus(); + } + + // Closes when focus goes elsewhere. No relatedTarget (window blur, Safari's + // unfocused clicks, Chrome blurring an item a render removes) is not leaving. + _onMenuFocusout(e) { + const to = e.relatedTarget; + if (to && !this._menuRef.value?.contains(to) && to !== this._btnRef.value) { + this._closeMenu(); + } + } + + _onMenuKey(e) { + const menu = this._menuRef.value; + if (!menu || !e.composedPath().includes(menu)) return; + const tabs = this._menuTabs; + const n = tabs.length; + const i = this._focusIndex; + let next = i; + if (e.key === 'ArrowDown') { + next = (i + 1) % n; + } else if (e.key === 'ArrowUp') { + next = (i - 1 + n) % n; + } else if (e.key === 'Home') { + next = 0; + } else if (e.key === 'End') { + next = n - 1; + } else if (e.key.length === 1 && e.key !== ' ' && !e.ctrlKey && !e.metaKey && !e.altKey) { + // Type-ahead: the next tab whose title starts with the letter. + const letter = e.key.toLowerCase(); + for (let k = 1; k <= n; k++) { + if ((tabs[(i + k) % n].title || '').toLowerCase().startsWith(letter)) { + next = (i + k) % n; + break; + } + } + } else if (e.key !== 'Escape') { + return; + } + e.preventDefault(); + e.stopPropagation(); + if (e.key === 'Escape') { + this._closeMenu(true); + } else { + this._focusIndex = next; + } + } + + _selectFromMenu(tab) { + this._closeMenu(true); + tab.select(); + } + + _renderTabMenu() { + return html` + + `; + } + get paneName() { return this.name || this.id.replace(/^pane-/, '') || 'pane'; } @@ -200,17 +455,33 @@ export class IdePaneElement extends LitElement { return html`
-
- +
+ this.requestUpdate()}>
+ ${when(hasMax, () => html` + >${this.maximized ? '⧉ Restore layout' : '⤢'} `)} ${when(hasCol, () => html`
+ ${this._menuOpen ? this._renderTabMenu() : nothing}
@@ -389,7 +661,7 @@ export class IdeTabElement extends LitElement { icon: { attribute: false }, }; - static styles = css` + static styles = [tabIconStyles, css` :host { display: inline-flex; align-items: center; @@ -425,33 +697,15 @@ export class IdeTabElement extends LitElement { border-bottom: 2px solid var(--accent-tab); } - .ide-tab-icon, - ::slotted([slot="icon"]), - .or-tab-icon { - display: inline-flex; - align-items: center; - justify-content: center; - flex: none; - width: 13px; - height: 13px; + .ide-tab-icon { opacity: 0.7; } - :host([active]) .ide-tab-icon, - :host([active]) ::slotted([slot="icon"]), - :host([active]) .or-tab-icon { + :host([active]) .ide-tab-icon { color: var(--accent-tab); opacity: 1; } - .ide-tab-icon svg, - ::slotted([slot="icon"]) svg, - .or-tab-icon svg { - width: 100%; - height: 100%; - display: block; - } - .ide-tab-title { user-select: none; padding-top: 0; @@ -477,7 +731,7 @@ export class IdeTabElement extends LitElement { background: var(--bg-hover); color: var(--sem-error); } - `; + `]; constructor() { super(); @@ -508,6 +762,11 @@ export class IdeTabElement extends LitElement { _onClick(e) { const path = e.composedPath ? e.composedPath() : [e.target]; if (path.some(el => el.classList?.contains('ide-tab-close'))) return; + this.select(); + } + + // Asks the layout to activate this tab. + select() { emitEvent(this, 'tab-select', { componentType: this.targetComponent }); } @@ -533,7 +792,7 @@ export class IdeTabElement extends LitElement { render() { return html` - ${this.icon ? html`${this.icon}` : nothing} + ${this.icon ? html`${this.icon}` : nothing} ${this.title || ''} ${this.closable ? html`✕` : nothing} `; @@ -1017,6 +1276,8 @@ export class GridLayoutManager extends EventEmitter { comp.contentDiv.hidden = false; this._setComponentActive(comp, true); this.closedComponents.delete(componentType); + // The pane's tab menu shows which tab is open. + pane.requestUpdate(); comp.container.fire('show'); comp.container.fire('open'); @@ -1039,6 +1300,8 @@ export class GridLayoutManager extends EventEmitter { this._setComponentActive(comp, false); comp.container.fire('hide'); this.closedComponents.add(componentType); + // The pane's tab menu lists only the open tabs. + this.panes[comp.paneName]?.requestUpdate(); if (autoSelectNext && this.activeTabs[comp.paneName] === componentType) { let nextComp = null; @@ -1062,15 +1325,20 @@ export class GridLayoutManager extends EventEmitter { this.emit('stateChanged'); } - focusComponent(componentType) { - const comp = this.components.get(componentType); - if (!comp) { + /** + * Activates a component's tab, mounting it first if needed. With reveal, + * also restores a maximized pane that hides the component's pane. + */ + focusComponent(componentType, options) { + if (!this.components.has(componentType)) { const factory = this.factories.get(componentType); - if (factory) { - this._mountComponent(componentType, factory); - } else { - return; - } + if (!factory) return; + this._mountComponent(componentType, factory); + } + const comp = this.components.get(componentType); + if (options?.reveal && comp && this.isPaneMaximized() + && !this.isPaneMaximized(comp.paneName)) { + this.restoreMaximized(); } this.activateTab(componentType); } diff --git a/src/web/src/main.js b/src/web/src/main.js index 9689abc77ec..749dc7f3c62 100644 --- a/src/web/src/main.js +++ b/src/web/src/main.js @@ -1300,9 +1300,10 @@ app.syncLayoutSize = syncLayoutSize; window.addEventListener('resize', syncLayoutSize); -// Focus a component tab, or re-create it if it was closed. -function focusComponent(componentType) { - app.goldenLayout.focusComponent(componentType); +// Focus a component tab, or re-create it if it was closed. `options.reveal` +// also restores a maximized pane that hides it (see GridLayoutManager). +function focusComponent(componentType, options) { + app.goldenLayout.focusComponent(componentType, options); } app.focusComponent = focusComponent; diff --git a/src/web/src/menu-bar.js b/src/web/src/menu-bar.js index ca4e7baa6f4..96f09ce7169 100644 --- a/src/web/src/menu-bar.js +++ b/src/web/src/menu-bar.js @@ -64,6 +64,10 @@ export function eventShortcut(e) { // Builds the bar and returns nothing; call app.rebuildMenuBar() after // updating app.customMenu to re-render live. export function createMenuBar(app) { + // Picking a window from a menu must show it, even behind a maximized pane. + const show = (componentType) => + () => app.focusComponent(componentType, { reveal: true }); + const staticMenus = [ { label: 'File', items: [ { label: 'Open DB...', action: () => showPathDialog(app, 'Open DB', 'read_db'), @@ -135,24 +139,24 @@ export function createMenuBar(app) { enabledWhen: () => !!app.designScale }, ]}, { label: 'Windows', items: [ - { label: 'Layout Viewer', action: () => app.focusComponent('LayoutViewer') }, - { label: '3D Viewer', action: () => app.focusComponent('3DViewer') }, - { label: 'Display Controls', action: () => app.focusComponent('DisplayControls') }, - { label: 'Inspector', action: () => app.focusComponent('Inspector') }, - { label: 'Selection Browser', - action: () => app.focusComponent('SelectHighlight') }, - { label: 'Tcl Console', action: () => app.focusComponent('TclConsole') }, - { label: 'Hierarchy Browser', action: () => app.focusComponent('Browser') }, - { label: 'Timing', action: () => app.focusComponent('TimingWidget') }, - { label: 'DRC Viewer', action: () => app.focusComponent('DRCWidget') }, - { label: 'Clock Tree', action: () => app.focusComponent('ClockWidget') }, - { label: 'Charts', action: () => app.focusComponent('ChartsWidget') }, - { label: 'Help', action: () => app.focusComponent('HelpWidget') }, + { label: 'Layout Viewer', action: show('LayoutViewer') }, + { label: 'Schematic', action: show('SchematicWidget') }, + { label: '3D Viewer', action: show('3DViewer') }, + { label: 'Display Controls', action: show('DisplayControls') }, + { label: 'Inspector', action: show('Inspector') }, + { label: 'Selection Browser', action: show('SelectHighlight') }, + { label: 'Tcl Console', action: show('TclConsole') }, + { label: 'Hierarchy Browser', action: show('Browser') }, + { label: 'Timing', action: show('TimingWidget') }, + { label: 'DRC Viewer', action: show('DRCWidget') }, + { label: 'Clock Tree', action: show('ClockWidget') }, + { label: 'Charts', action: show('ChartsWidget') }, + { label: 'Help', action: show('HelpWidget') }, { type: 'separator' }, { label: 'Reset to Default Layout', action: () => app.resetLayout() }, ]}, { label: 'Help', items: [ - { label: 'Keyboard Shortcuts', action: () => app.focusComponent('HelpWidget') }, + { label: 'Keyboard Shortcuts', action: show('HelpWidget') }, ]}, ]; diff --git a/src/web/src/schematic-widget.js b/src/web/src/schematic-widget.js index 432092500fd..46c95195172 100644 --- a/src/web/src/schematic-widget.js +++ b/src/web/src/schematic-widget.js @@ -120,7 +120,7 @@ export class SchematicWidget { this.container.element.appendChild(this.element); // Button listeners - this.controls.querySelector('#schematic-refresh').addEventListener('click', () => this.refresh()); + this.controls.querySelector('#schematic-refresh').addEventListener('click', () => this._onRefresh()); this.controls.querySelector('#schematic-back').addEventListener('click', () => this._goBackSchematic()); this.controls.querySelector('#schematic-fit').addEventListener('click', () => this.fitView()); this.controls.querySelector('#schematic-zoom-in').addEventListener('click', () => this._zoomStep(1.5)); @@ -278,6 +278,8 @@ export class SchematicWidget { return { netlist: this._currentNetlist, selectedInstanceName: this.appState.selectedInstanceName || null, + // The instance Refresh redraws while this view is shown. + instName: this._instName, }; } @@ -332,6 +334,7 @@ export class SchematicWidget { } this._setBackButtonEnabled(); this._leaveTimingSchematic(); + this._instName = snapshot.instName; if (!snapshot.selectedInstanceName) { return true; } @@ -466,7 +469,7 @@ export class SchematicWidget { if (load === 'path') { this._loadPathSchematic(++this._timingRequestId); } else if (load === 'refresh') { - this.refresh(); + this._onRefresh(); } } @@ -971,22 +974,30 @@ export class SchematicWidget { }; apply(faninEl, detail.fanin, detail.fanin_depth); apply(fanoutEl, detail.fanout, detail.fanout_depth); - this.refresh(); + // The cone's instance, which a path pin picks without selecting it. + this.refresh(detail.inst_name); + // Applying with "sync schematic" asks to see it, past a maximized pane. if (this.appState.focusComponent) { - this.appState.focusComponent('SchematicWidget'); + this.appState.focusComponent('SchematicWidget', { reveal: true }); } } // ── Refresh ────────────────────────────────────────────────────────────── + // Redraws the instance last asked for, including one a timing cone picked + // without selecting it. + _onRefresh() { + return this.refresh(this._instName); + } + // Resolve to whether a schematic was drawn so callers can sequence updates. - async refresh() { + async refresh(instName = this.appState.selectedInstanceName) { + this._instName = instName; if (!this._netlistsvgReady) { this.setStatus(this._unreadyStatus()); return false; } - const instName = this.appState.selectedInstanceName; if (!instName) { this.setStatus(kIdleStatus); return false; @@ -1084,6 +1095,7 @@ export class SchematicWidget { // Record Back history only after expansion renders. this._pushSchematicHistory(previousSnapshot); this._leaveTimingSchematic(); + this._instName = instName; return true; } catch (err) { if (isCurrent()) this.setStatus(`Error: ${err}`); diff --git a/src/web/src/timing-widget.js b/src/web/src/timing-widget.js index dc0a095ed5b..efb25ed53b7 100644 --- a/src/web/src/timing-widget.js +++ b/src/web/src/timing-widget.js @@ -39,6 +39,8 @@ export class TimingWidget { this._selectedPathIndex = -1; this._detailTab = 'data'; this._selectedDetailIndex = -1; + // app.selectionToken when a path row was last picked (_coneTarget). + this._rowSelectionToken = null; // Default to sorting by slack, matching the Qt GUI. this._sortCol = 'slack'; this._sortAscending = true; @@ -310,7 +312,7 @@ export class TimingWidget { this._coneApplyBtn = document.createElement('button'); this._coneApplyBtn.className = 'or-btn'; this._coneApplyBtn.textContent = 'Cone'; - this._coneApplyBtn.title = 'Show the timing cone for the selected instance'; + this._coneApplyBtn.title = 'Show the timing cone for the selected path pin or instance'; this._coneClearBtn = document.createElement('button'); this._coneClearBtn.className = 'or-btn'; this._coneClearBtn.textContent = 'Clear'; @@ -326,11 +328,19 @@ export class TimingWidget { return panel; } - // The cone target: the currently selected instance. (The backend also - // accepts pin_name for a future per-pin cone, but the web UI has no pin - // selection yet, so we always target the instance.) + // The cone target: the pin of the path row picked last, unless any selection + // (layout, Inspector, Charts…) came after it; else the selected instance. + // The backend prefers pin_name and falls back to inst_name. _coneTarget() { - return this._app.selectedInstanceName || ''; + const row = this._detailRows?.[this._selectedDetailIndex]; + const node = row && this._detailNodes[row.node]; + const inst = this._app.selectedInstanceName || ''; + if (node?.pin && this._app.selectionToken === this._rowSelectionToken) { + // A port's inst is empty; its name alone can't tell (3DBlox + // prefixes a chiplet port with its chip-inst). + return { pin: node.pin, inst: node.inst || '' }; + } + return { pin: '', inst }; } async _applyCone() { @@ -340,9 +350,9 @@ export class TimingWidget { this._coneStatus.textContent = 'select fanin and/or fanout'; return; } - const inst = this._coneTarget(); - if (!inst) { - this._coneStatus.textContent = 'select an instance first'; + const { pin, inst } = this._coneTarget(); + if (!pin && !inst) { + this._coneStatus.textContent = 'select an instance or a path pin first'; return; } const req = { @@ -354,6 +364,7 @@ export class TimingWidget { color_mode: this._coneColorMode.value, inst_name: inst, }; + if (pin) req.pin_name = pin; this._coneApplyBtn.disabled = true; this._coneStatus.textContent = 'computing…'; try { @@ -701,24 +712,31 @@ export class TimingWidget { rows[idx].classList.add('timing-selected-row'); rows[idx].scrollIntoView({ block: 'nearest' }); this._detailTableContainer.focus(); + this._rowSelectionToken = this._app.selectionToken; const paths = this._currentTab === 'setup' ? this._setupPaths : this._holdPaths; const path = paths[this._selectedPathIndex]; - const nodes = this._detailTab === 'data' ? path.data_nodes : path.capture_nodes; - const node = nodes[this._detailRows[idx].node]; + const node = this._detailNodes[this._detailRows[idx].node]; this._app.websocketManager.request(this._highlightRequest( path, this._selectedPathIndex, { pin_name: node.pin })) .then(() => this._refreshOverlay()); } + // The nodes the detail table shows: the selected path's data or capture side. + get _detailNodes() { + const paths = this._currentTab === 'setup' ? this._setupPaths : this._holdPaths; + const path = paths[this._selectedPathIndex]; + if (!path) return []; + return (this._detailTab === 'data' ? path.data_nodes : path.capture_nodes) || []; + } + _renderDetailTable() { this._detailTable.innerHTML = ''; this._selectedDetailIndex = -1; const paths = this._currentTab === 'setup' ? this._setupPaths : this._holdPaths; if (this._selectedPathIndex < 0 || this._selectedPathIndex >= paths.length) return; - const path = paths[this._selectedPathIndex]; - const nodes = this._detailTab === 'data' ? path.data_nodes : path.capture_nodes; + const nodes = this._detailNodes; const thead = document.createElement('thead'); const hr = document.createElement('tr'); diff --git a/src/web/src/ui-utils.js b/src/web/src/ui-utils.js index b5e12c745ec..6a01a807f59 100644 --- a/src/web/src/ui-utils.js +++ b/src/web/src/ui-utils.js @@ -817,7 +817,7 @@ export function installWheelPanning(map, wheelZoomEnabled) { map.getContainer().addEventListener('wheel', (e) => { e.preventDefault(); if (wheelZoomEnabled() === e.ctrlKey) { - const [dx, dy] = wheelDeltaPx(e, map.getContainer()); + const [dx, dy] = wheelDeltaPx(e, () => map.getContainer().clientHeight); map.panBy([dx, dy], { animate: false }); return; } @@ -830,14 +830,16 @@ export function installWheelPanning(map, wheelZoomEnabled) { // A wheel event's scroll amount in CSS pixels. deltaMode is not always pixels: // Firefox reports lines, and a page-mode event (rare, but produced by some // remote-desktop stacks) means a viewport at a time. Treating either as pixels -// would make one notch pan by a couple of pixels. -function wheelDeltaPx(e, container) { +// would make one notch pan by a couple of pixels. `pagePx()` gives the +// viewport's size along the direction the caller scrolls; it is called only +// for page-mode events, keeping the layout read off the common path. +export function wheelDeltaPx(e, pagePx) { const kLineHeightPx = 16; let scale = 1; if (e.deltaMode === 1) { scale = kLineHeightPx; } else if (e.deltaMode === 2) { - scale = container.clientHeight || kLineHeightPx; + scale = pagePx() || kLineHeightPx; } return [e.deltaX * scale, e.deltaY * scale]; } diff --git a/src/web/test/js/test-ide-layout.js b/src/web/test/js/test-ide-layout.js index ecadc69fbc2..f1deb87eb38 100644 --- a/src/web/test/js/test-ide-layout.js +++ b/src/web/test/js/test-ide-layout.js @@ -9,6 +9,37 @@ import { TabIcon, COMPONENT_CONFIG } from '../../src/grid-layout.js'; +const PointerEvt = window.PointerEvent || window.MouseEvent; + +// jsdom has no layout: give a tab strip the geometry a browser would. +function stubTabStrip(tabsEl, { scrollWidth, clientWidth }) { + let scrollLeft = 0; + Object.defineProperty(tabsEl, 'scrollWidth', { value: scrollWidth, configurable: true }); + Object.defineProperty(tabsEl, 'clientWidth', { value: clientWidth, configurable: true }); + Object.defineProperty(tabsEl, 'scrollLeft', { + get: () => scrollLeft, + set: (v) => { scrollLeft = v; }, + configurable: true, + }); +} + +// A keydown that crosses into the pane's shadow DOM; returns the event. +function pressKey(target, key) { + const e = new window.KeyboardEvent('keydown', { + key, bubbles: true, composed: true, cancelable: true, + }); + target.dispatchEvent(e); + return e; +} + +// Lets slotchange callbacks run. +const tick = () => new Promise(resolve => setTimeout(resolve, 0)); + +const menuOf = (pane) => pane.shadowRoot.querySelector('.ide-tab-menu'); +const menuItems = (pane) => [...pane.shadowRoot.querySelectorAll('.ide-tab-menu-item')]; +const focusedTitle = (pane) => pane.shadowRoot.activeElement + ?.querySelector('.ide-tab-menu-title')?.textContent; + describe('GridLayoutManager', () => { let containerEl; let layout; @@ -20,6 +51,27 @@ describe('GridLayoutManager', () => { layout = new GridLayoutManager(containerEl); }); + async function mountRightPane() { + for (const type of ['Inspector', 'Browser', 'TimingWidget', 'ChartsWidget']) { + layout.registerComponentFactoryFunction(type, () => {}); + } + layout.loadLayout({}); + const pane = layout.panes.right; + await pane.updateComplete; + return { pane, tabsEl: pane.shadowRoot.querySelector('.ide-tabs') }; + } + + // The right pane; with `open`, its tab menu too. + async function mountMenuPane({ open = false } = {}) { + const { pane, tabsEl } = await mountRightPane(); + const btn = pane.shadowRoot.querySelector('.ide-btn-tab-menu'); + if (open) { + btn.click(); + await pane.updateComplete; + } + return { pane, tabsEl, btn }; + } + it('initializes the CSS Grid DOM structure when empty', () => { assert.ok(containerEl.classList.contains('ide-layout')); assert.ok(containerEl.querySelector('#pane-left')); @@ -349,6 +401,320 @@ describe('GridLayoutManager', () => { assert.ok(!bottomPane.collapsed); }); + it('focusComponent with reveal restores a maximized pane that hides the target', () => { + layout.registerComponentFactoryFunction('LayoutViewer', () => {}); + layout.registerComponentFactoryFunction('TimingWidget', () => {}); + layout.registerComponentFactoryFunction('ChartsWidget', () => {}); + layout.loadLayout({}); + + // Programmatic focus leaves the user's maximized pane alone. + layout.maximizePane('main'); + layout.focusComponent('ChartsWidget'); + assert.ok(containerEl.classList.contains('maximized-main')); + + layout.focusComponent('ChartsWidget', { reveal: true }); + assert.ok(!layout.isPaneMaximized()); + assert.ok(!containerEl.classList.contains('maximized-main')); + assert.equal(layout.activeTabs.right, 'ChartsWidget'); + + // The target is in the maximized pane itself: nothing to restore. + layout.maximizePane('right'); + layout.focusComponent('TimingWidget', { reveal: true }); + assert.ok(containerEl.classList.contains('maximized-right')); + assert.equal(layout.activeTabs.right, 'TimingWidget'); + + layout.focusComponent('ChartsWidget', null); + assert.equal(layout.activeTabs.right, 'ChartsWidget'); + }); + + it('shows the ▼ tab menu button on every pane', async () => { + for (const type of ['DisplayControls', 'LayoutViewer', 'TclConsole', 'Inspector']) { + layout.registerComponentFactoryFunction(type, () => {}); + } + layout.loadLayout({}); + for (const name of ['left', 'main', 'bottom', 'right']) { + const pane = layout.panes[name]; + await pane.updateComplete; + assert.equal(pane.shadowRoot.querySelector('.ide-btn-tab-menu')?.textContent, '▼', name); + } + + // A pane with a single tab lists it. + const left = layout.panes.left; + left.shadowRoot.querySelector('.ide-btn-tab-menu').click(); + await left.updateComplete; + assert.deepEqual( + menuItems(left).map(item => item.textContent.trim().replace(/\s+/g, ' ')), + ['✓ Display Controls']); + }); + + it('lists the open tabs in the tab menu and activates the chosen one', async () => { + const { pane, btn } = await mountMenuPane(); + layout.closeComponent('Browser'); + assert.equal(btn.getAttribute('aria-expanded'), 'false'); + btn.click(); + await pane.updateComplete; + assert.equal(btn.getAttribute('aria-expanded'), 'true'); + + const items = menuItems(pane); + assert.deepEqual( + items.map(item => item.querySelector('.ide-tab-menu-title').textContent), + ['Inspector', 'Timing', 'Charts']); + assert.deepEqual( + items.map(item => item.getAttribute('aria-checked')), + ['true', 'false', 'false']); + assert.ok(items[2].querySelector('.ide-tab-icon svg')); + + // Opening focuses the open tab's item; arrows, Home and End move + // between items, which stay out of the Tab order. + assert.ok(items.every(item => item.getAttribute('tabindex') === '-1')); + assert.equal(pane.shadowRoot.activeElement, items[0]); + const key = async (k) => { + pressKey(pane.shadowRoot.activeElement, k); + await pane.updateComplete; + }; + await key('ArrowUp'); + assert.equal(pane.shadowRoot.activeElement, items[2]); + await key('ArrowDown'); + assert.equal(pane.shadowRoot.activeElement, items[0]); + await key('End'); + assert.equal(pane.shadowRoot.activeElement, items[2]); + await key('Home'); + assert.equal(pane.shadowRoot.activeElement, items[0]); + await key('End'); + + items[2].click(); + await pane.updateComplete; + assert.equal(layout.activeTabs.right, 'ChartsWidget'); + assert.equal(menuOf(pane), null); + assert.equal(btn.getAttribute('aria-expanded'), 'false'); + assert.equal(pane.shadowRoot.activeElement, btn, 'focus returns to the ▼'); + }); + + it('lets a click on the tab menu button reach document listeners', async () => { + const { btn } = await mountMenuPane(); + + // The menu bar and the layer context menu close on a document click. + let clicks = 0; + const onClick = () => { clicks++; }; + document.addEventListener('click', onClick); + try { + btn.click(); + assert.equal(clicks, 1); + } finally { + document.removeEventListener('click', onClick); + } + }); + + it('keeps keyboard focus and Escape within the tab menu', async () => { + const { pane, btn } = await mountMenuPane(); + const focused = () => pane.shadowRoot.activeElement; + const open = async () => { + btn.click(); + await pane.updateComplete; + assert.ok(menuOf(pane)); + }; + const press = async (k) => { + const e = pressKey(focused(), k); + await pane.updateComplete; + return e; + }; + + // Like main.js's shortcuts: registered first, in document capture. + const seen = []; + const onKeydown = (e) => seen.push(e.key); + document.addEventListener('keydown', onKeydown, true); + try { + await open(); + assert.ok(!pressKey(document, 'Escape').defaultPrevented); + await pane.updateComplete; + assert.ok(menuOf(pane), 'an Escape outside the menu leaves it open'); + assert.equal(seen.length, 1); + + const e = await press('Escape'); + assert.ok(e.defaultPrevented); + assert.equal(menuOf(pane), null); + assert.equal(focused(), btn); + assert.equal(seen.length, 1, 'the menu\'s Escape stops at the menu'); + + // A letter jumps to the next item starting with it, and is no + // shortcut ('t' toggles the theme, 'k' the ruler). + await open(); + assert.ok((await press('t')).defaultPrevented); + assert.equal(focusedTitle(pane), 'Timing'); + await press('h'); + assert.equal(focusedTitle(pane), 'Hierarchy', 'wraps past the end'); + assert.ok((await press('x')).defaultPrevented, 'no match'); + assert.equal(focusedTitle(pane), 'Hierarchy'); + assert.equal(seen.length, 1); + + // Enter is left to the button. + assert.ok(!(await press('Enter')).defaultPrevented); + assert.equal(seen.length, 2); + await press('Escape'); + } finally { + document.removeEventListener('keydown', onKeydown, true); + } + + // Focus going within the menu or to its button keeps it open; no + // destination (window blur, Safari clicks, Chrome removing a focused + // item) keeps it open too; anywhere else closes it. + await open(); + const focusout = async (relatedTarget) => { + menuItems(pane)[0].dispatchEvent(new window.FocusEvent('focusout', { + bubbles: true, composed: true, relatedTarget, + })); + await pane.updateComplete; + }; + await focusout(menuItems(pane)[1]); + assert.ok(menuOf(pane)); + await focusout(btn); + assert.ok(menuOf(pane)); + await focusout(null); + assert.ok(menuOf(pane)); + await focusout(document.body); + assert.equal(menuOf(pane), null); + + await open(); + menuItems(pane)[0].dispatchEvent( + new PointerEvt('pointerdown', { bubbles: true, composed: true })); + await pane.updateComplete; + assert.ok(menuOf(pane), 'a pointerdown inside the menu keeps it open'); + document.body.dispatchEvent(new PointerEvt('pointerdown', { bubbles: true })); + await pane.updateComplete; + assert.equal(menuOf(pane), null); + + // Maximizing the pane closes it too. + await open(); + layout.maximizePane('right'); + await pane.updateComplete; + assert.equal(menuOf(pane), null); + }); + + it('updates the open tab menu when the active tab changes', async () => { + const { pane } = await mountMenuPane({ open: true }); + + // E.g. a selection response focusing another tab while the menu is open. + layout.activateTab('TimingWidget'); + await pane.updateComplete; + + const checked = menuItems(pane) + .filter(item => item.getAttribute('aria-checked') === 'true') + .map(item => item.querySelector('.ide-tab-menu-title').textContent); + assert.deepEqual(checked, ['Timing']); + }); + + it('closes the tab menu from the button that opened it', async () => { + const { pane, btn } = await mountMenuPane({ open: true }); + + // Chrome moves focus to the ▼ on mousedown; that must not close the + // menu, or the click would open it again. + menuItems(pane)[0].dispatchEvent(new window.FocusEvent('focusout', { + bubbles: true, composed: true, relatedTarget: btn, + })); + await pane.updateComplete; + assert.ok(menuOf(pane)); + + btn.click(); + await pane.updateComplete; + assert.equal(menuOf(pane), null); + assert.equal(pane.shadowRoot.activeElement, btn); + }); + + it('keeps focus in the tab menu when the focused item goes away', async () => { + const { pane, btn } = await mountMenuPane({ open: true }); + pressKey(pane.shadowRoot.activeElement, 'End'); + await pane.updateComplete; + assert.equal(focusedTitle(pane), 'Charts'); + + // Chrome blurs a focused node as it removes it; jsdom does not. + const focused = pane.shadowRoot.activeElement; + const remove = focused.remove.bind(focused); + focused.remove = () => { + focused.dispatchEvent(new window.FocusEvent('focusout', { + bubbles: true, composed: true, relatedTarget: null, + })); + remove(); + }; + + // E.g. a Tcl command closing the window while the menu is open. + layout.closeComponent('ChartsWidget'); + await pane.updateComplete; + assert.ok(menuOf(pane)); + assert.equal(focusedTitle(pane), 'Timing', 'on the neighbouring item'); + + // A close the user did not ask for still hands focus back to the ▼. + layout.maximizePane('right'); + await pane.updateComplete; + assert.equal(menuOf(pane), null); + assert.equal(pane.shadowRoot.activeElement, btn); + }); + + it('disables the tab menu while the pane has no open tabs', async () => { + const { pane, btn } = await mountMenuPane({ open: true }); + for (const type of ['Inspector', 'Browser', 'TimingWidget']) { + layout.closeComponent(type); + } + await pane.updateComplete; + assert.ok(menuOf(pane)); + assert.equal(btn.disabled, false); + + layout.closeComponent('ChartsWidget'); + await pane.updateComplete; + assert.equal(menuOf(pane), null, 'closing the last tab closes the menu'); + assert.equal(btn.disabled, true); + + layout.focusComponent('ChartsWidget'); + await pane.updateComplete; + assert.equal(btn.disabled, false); + }); + + it('lists a tab added while the tab menu is open', async () => { + const { pane } = await mountMenuPane({ open: true }); + + const extra = document.createElement('ide-tab'); + extra.slot = 'tabs'; + extra.title = 'Extra'; + pane.appendChild(extra); + await tick(); + await pane.updateComplete; + + const titles = menuItems(pane) + .map(item => item.querySelector('.ide-tab-menu-title').textContent); + assert.ok(titles.includes('Extra'), titles.join()); + }); + + it('scrolls an overflowing tab strip horizontally with a vertical wheel', async () => { + const { tabsEl } = await mountRightPane(); + const spin = (init) => { + const e = new window.WheelEvent('wheel', { bubbles: true, cancelable: true, ...init }); + tabsEl.dispatchEvent(e); + return e; + }; + + stubTabStrip(tabsEl, { scrollWidth: 300, clientWidth: 300 }); + assert.ok(!spin({ deltaY: 100 }).defaultPrevented); + assert.equal(tabsEl.scrollLeft, 0); + + stubTabStrip(tabsEl, { scrollWidth: 700, clientWidth: 300 }); + assert.ok(spin({ deltaY: 100 }).defaultPrevented); + assert.equal(tabsEl.scrollLeft, 100); + + spin({ deltaY: 3, deltaMode: 1 }); + assert.equal(tabsEl.scrollLeft, 148); + + // The strip scrolls sideways, so a page is its width (300). + spin({ deltaY: 1, deltaMode: 2 }); + assert.equal(tabsEl.scrollLeft, 448); + + // Horizontal gestures are left to the browser. + assert.ok(!spin({ deltaX: 50, deltaY: 10 }).defaultPrevented); + assert.equal(tabsEl.scrollLeft, 448); + + // So are Ctrl+wheel and trackpad pinch, which zoom the page. + assert.ok(!spin({ deltaY: 100, ctrlKey: true }).defaultPrevented); + assert.equal(tabsEl.scrollLeft, 448); + }); + it('persists and restores layout dimensions and active tabs', () => { layout.registerComponentFactoryFunction('DisplayControls', () => {}); layout.registerComponentFactoryFunction('LayoutViewer', () => {}); @@ -422,13 +788,15 @@ describe('GridLayoutManager', () => { await pane.updateComplete; assert.ok(pane.hasAttribute('maximized')); assert.ok(pane.maximized); - assert.equal(maxBtn.textContent, '⧉'); + assert.equal(maxBtn.textContent.trim(), '⧉ Restore layout'); + assert.ok(maxBtn.classList.contains('ide-btn-restore')); pane.setMaximized(false); await pane.updateComplete; assert.ok(!pane.hasAttribute('maximized')); assert.ok(!pane.maximized); assert.equal(maxBtn.textContent, '⤢'); + assert.ok(!maxBtn.classList.contains('ide-btn-restore')); pane.remove(); }); @@ -465,7 +833,6 @@ describe('GridLayoutManager', () => { dragDetail = e.detail; }); - const PointerEvt = window.PointerEvent || window.MouseEvent; splitter.dispatchEvent(new PointerEvt('pointerdown', { bubbles: true, clientX: 100, clientY: 50 })); assert.ok(splitter.classList.contains('dragging')); assert.ok(document.body.classList.contains('is-resizing')); @@ -492,7 +859,8 @@ describe('GridLayoutManager', () => { await pane.updateComplete; assert.ok(pane.shadowRoot.querySelector('.ide-header')); - assert.ok(pane.shadowRoot.querySelector('.ide-tabs')); + // The ide-tab elements are role="tab"; ARIA wants them in a tablist. + assert.equal(pane.shadowRoot.querySelector('.ide-tabs').getAttribute('role'), 'tablist'); assert.ok(pane.shadowRoot.querySelector('.ide-controls')); assert.ok(pane.shadowRoot.querySelector('.ide-content')); assert.ok(pane.shadowRoot.querySelector('#btn-maximize-structure')); @@ -573,17 +941,17 @@ describe('GridLayoutManager', () => { // Test TabIcon enum rendering tab.icon = TabIcon.LAYOUT; await tab.updateComplete; - assert.ok(tab.shadowRoot.querySelector('.or-tab-icon svg')); + assert.ok(tab.shadowRoot.querySelector('.ide-tab-icon svg')); // Test updating to another TabIcon tab.icon = TabIcon.TCL_CONSOLE; await tab.updateComplete; - assert.ok(tab.shadowRoot.querySelector('.or-tab-icon svg')); + assert.ok(tab.shadowRoot.querySelector('.ide-tab-icon svg')); // Tabs without an icon do not render an icon container tab.icon = null; await tab.updateComplete; - assert.equal(tab.shadowRoot.querySelector('.or-tab-icon'), null); + assert.equal(tab.shadowRoot.querySelector('.ide-tab-icon'), null); tab.remove(); }); diff --git a/src/web/test/js/test-menu-bar.js b/src/web/test/js/test-menu-bar.js index 21d78d7c220..ef2ec261138 100644 --- a/src/web/test/js/test-menu-bar.js +++ b/src/web/test/js/test-menu-bar.js @@ -378,3 +378,24 @@ describe('Options menu', () => { assert.ok(row.classList.contains('disabled')); }); }); + +describe('Windows menu', () => { + it('reveals the window it opens, even behind a maximized pane', () => { + document.body.innerHTML = ''; + const focused = []; + createMenuBar(optionsApp({ + focusComponent(...args) { focused.push(args); }, + })); + + rowByLabel(openMenu('Windows'), 'Charts').click(); + // Closable, so the menu must be able to bring it back. + rowByLabel(openMenu('Windows'), 'Schematic').click(); + rowByLabel(openMenu('Help'), 'Keyboard Shortcuts').click(); + + assert.deepEqual(focused, [ + ['ChartsWidget', { reveal: true }], + ['SchematicWidget', { reveal: true }], + ['HelpWidget', { reveal: true }], + ]); + }); +}); diff --git a/src/web/test/js/test-schematic-widget.js b/src/web/test/js/test-schematic-widget.js index da6da23f7f1..c8d690c72ce 100644 --- a/src/web/test/js/test-schematic-widget.js +++ b/src/web/test/js/test-schematic-widget.js @@ -1674,6 +1674,29 @@ describe('SchematicWidget timing path overlay', () => { container.element.remove(); }); + it('redraws the shown view\'s instance on Refresh after expand and Back', async () => { + const cones = []; + const { widget, container } = makeRenderingPathWidget(msg => { + if (msg.type === 'schematic_cone') cones.push(msg.inst_name); + return Promise.resolve(netlistWith(msg.inst_name)); + }); + // A timing cone draws u1 without selecting it. + widget.appState.selectedInstanceName = 'u0'; + await widget.refresh('u1'); + + await widget._expandFromInstance('u2', widget._currentSchematicSnapshot()); + cones.length = 0; + await widget._onRefresh(); + assert.deepEqual(cones, ['u2']); + + await widget._expandFromInstance('u3', widget._currentSchematicSnapshot()); + assert.equal(await widget._goBackSchematic(), true); + cones.length = 0; + await widget._onRefresh(); + assert.deepEqual(cones, ['u2']); + container.element.remove(); + }); + it('reloads a path once something else was drawn over it', async () => { const requests = []; const { widget, container } = makeRenderingPathWidget(msg => { @@ -2540,7 +2563,7 @@ describe('SchematicWidget.syncCone', () => { const stub = { controls, refreshed: 0, - refresh() { this.refreshed++; }, + refresh(inst) { this.refreshed++; this.refreshedFor = inst; }, appState: {}, }; return stub; @@ -2579,6 +2602,55 @@ describe('SchematicWidget.syncCone', () => { }); assert.deepEqual(depths(s), ['2', '10']); }); + + // The timing panel's Apply asks to see the schematic, which a maximized + // right pane would otherwise hide. + it('reveals the schematic it synced', () => { + const s = makeStub(); + const focused = []; + s.appState.focusComponent = (...args) => focused.push(args); + SchematicWidget.prototype.syncCone.call(s, { inst_name: 'b0', fanin: true }); + assert.deepEqual(focused, [['SchematicWidget', { reveal: true }]]); + // The cone's instance, which a timing path pin can pick unselected. + assert.equal(s.refreshedFor, 'b0'); + }); +}); + +// The real refresh() on a stand-in, recording the instances it asks for. +describe('SchematicWidget.refresh', () => { + function makeStub() { + const requested = []; + const stub = Object.create(SchematicWidget.prototype); + stub._netlistsvgReady = true; + stub._displayed = true; + stub._timingRequestId = 0; + stub.showTimingPath = () => {}; + stub.renderNetlist = async () => false; + stub.controls = document.createElement('div'); + stub.controls.innerHTML = + '' + + ''; + stub.setStatus = () => {}; + stub.appState = { + selectedInstanceName: '', + websocketManager: { + readyPromise: Promise.resolve(), + request(msg) { + requested.push(msg.inst_name); + return Promise.resolve({}); + }, + }, + }; + return { stub, requested }; + } + + it('redraws the instance a timing cone picked when Refresh is pressed', async () => { + const { stub, requested } = makeStub(); + stub.refresh('b0'); // syncCone, for a path pin nothing selected + stub._onRefresh(); + await new Promise(resolve => setTimeout(resolve, 0)); + assert.deepEqual(requested, ['b0', 'b0']); + }); }); // A stand-in again: building the widget needs a window. diff --git a/src/web/test/js/test-timing-widget.js b/src/web/test/js/test-timing-widget.js index 13d3081a1d7..be7189a0287 100644 --- a/src/web/test/js/test-timing-widget.js +++ b/src/web/test/js/test-timing-widget.js @@ -5,6 +5,7 @@ import './setup-dom.js'; import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { TimingWidget, detailRows, fmtTime } from '../../src/timing-widget.js'; +import { beginSelection } from '../../src/ui-utils.js'; // jsdom does not implement scrollIntoView; stub it so _selectPathRow runs. if (!window.HTMLElement.prototype.scrollIntoView) { @@ -370,6 +371,113 @@ describe('TimingWidget path table sorting', () => { }); }); +describe('TimingWidget cone target', () => { + // As the server sends them: a port has no instance, and a 3DBlox chiplet's + // names carry its chip-inst prefix. + const nodes = [ + { pin: 'in1', inst: '' }, + { pin: '_12_/A', inst: '_12_' }, + { pin: '_12_/Z', inst: '_12_' }, + { pin: 'chip/in2', inst: '' }, + { pin: 'chip/_13_/A', inst: 'chip/_13_' }, + ]; + + // One setup path, selected, so its detail table lists `nodes`. + function makeWidget(app) { + const widget = new TimingWidget(app, () => {}); + widget.showPaths('setup', [makePath(-0.1, '_12_/Z', { data_nodes: nodes })]); + widget._selectPathRow(0); + return widget; + } + + // Presses Cone with "Sync schematic" ticked. + async function applyCone(widget, app) { + const synced = []; + const onSync = (e) => synced.push(e.detail.inst_name); + document.addEventListener('openroad-cone-sync', onSync); + try { + app.requests.length = 0; + widget._coneSyncSchematic.checked = true; + await widget._applyCone(); + } finally { + document.removeEventListener('openroad-cone-sync', onSync); + } + return { cone: app.requests.find(r => r.type === 'timing_cone'), synced }; + } + + it('targets the pin of the picked path row and syncs its instance', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + widget._selectDetailRow(2); + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone.pin_name, '_12_/Z'); + assert.equal(cone.inst_name, '_12_'); + assert.deepEqual(synced, ['_12_']); + }); + + it('targets an instance selected after the row instead', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + widget._selectDetailRow(2); + beginSelection(app); + app.selectedInstanceName = 'u9'; + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone.pin_name, undefined); + assert.equal(cone.inst_name, 'u9'); + assert.deepEqual(synced, ['u9']); + }); + + it('targets the instance when it is selected again after the row', async () => { + const app = createMockApp(); + app.selectedInstanceName = 'u9'; + const widget = makeWidget(app); + widget._selectDetailRow(2); + // Same name as before the row: only the selection token tells them apart. + beginSelection(app); + const { cone } = await applyCone(widget, app); + assert.equal(cone.pin_name, undefined); + assert.equal(cone.inst_name, 'u9'); + }); + + it('cones a port row without syncing the schematic', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + widget._selectDetailRow(0); + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone.pin_name, 'in1'); + assert.equal(cone.inst_name, ''); + assert.deepEqual(synced, []); + }); + + it('cones a chiplet port without syncing the schematic', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + widget._selectDetailRow(3); + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone.pin_name, 'chip/in2'); + assert.equal(cone.inst_name, ''); + assert.deepEqual(synced, []); + }); + + it('syncs a chiplet pin\'s prefixed instance', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + widget._selectDetailRow(4); + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone.pin_name, 'chip/_13_/A'); + assert.deepEqual(synced, ['chip/_13_']); + }); + + it('asks for a target when there is none', async () => { + const app = createMockApp(); + const widget = makeWidget(app); + const { cone, synced } = await applyCone(widget, app); + assert.equal(cone, undefined); + assert.deepEqual(synced, []); + assert.equal(widget._coneStatus.textContent, 'select an instance or a path pin first'); + }); +}); + describe('TimingWidget detail table columns', () => { const node = (pin) => ({ pin, fanout: 1, rise: true, time: 0, delay: 0, slew: 0, load: 0, diff --git a/src/web/test/js/test-ui-utils.js b/src/web/test/js/test-ui-utils.js index 50a2399958b..fae3c1baa96 100644 --- a/src/web/test/js/test-ui-utils.js +++ b/src/web/test/js/test-ui-utils.js @@ -442,6 +442,13 @@ describe('installWheelPanning', () => { assert.deepEqual(calls.zoom, []); }); + it('pans a page-mode notch by the map\'s height', () => { + const { map, calls, fire } = makeWheelMap({ clientHeight: 600 }); + installWheelPanning(map, () => false); + fire({ deltaY: 1, deltaMode: 2 }); + assert.deepEqual(calls.pan, [[0, 600]]); + }); + it('zooms on Ctrl+wheel when the preference is off', () => { const { map, calls, fire } = makeWheelMap({ zoom: 3 }); installWheelPanning(map, () => false);