From 6fb38daba5932b7b44c564bdf0686ce6ec69af23 Mon Sep 17 00:00:00 2001 From: Prabhaav Pillai Date: Wed, 18 Nov 2026 15:38:13 -0500 Subject: [PATCH] =?UTF-8?q?The=20outside-click=20handler=20treated=20Undo/?= =?UTF-8?q?Redo=20as=20outside=20the=20editor,=20clearing=20selection=20an?= =?UTF-8?q?d=20hiding=20widget=20controls.=20It=20also=20misclassified=20?= =?UTF-8?q?=E2=80=9CAdd=20to=20layout=E2=80=9D=20after=20its=20button=20wa?= =?UTF-8?q?s=20removed=20during=20the=20click.=20Both=20broke=20browser=20?= =?UTF-8?q?workflows.=09Fixed=20using=20the=20event=E2=80=99s=20original?= =?UTF-8?q?=20propagation=20path=20to=20identify=20clicks=20inside=20the?= =?UTF-8?q?=20editor.=20Opening=20Edit=20after=20deselection=20showed=20a?= =?UTF-8?q?=20blank=20picker=20and=20no=20coordinate=20controls.=09Fixed?= =?UTF-8?q?=20by=20selecting=20an=20active=20widget,=20with=20a=20fallback?= =?UTF-8?q?=20to=20the=20first=20widget.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../galaxy/tests/browser/widget-layers.cjs | 3 +++ .../galaxy/tests/test_edit_panel_reveal.mjs | 15 +++++++++++++++ openpilot/starpilot/galaxy/web/css/settings.css | 6 +++--- .../starpilot/galaxy/web/js/onroad-layout.js | 12 +++++++----- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs b/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs index cf4aef836a..a6260cd99d 100644 --- a/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs +++ b/openpilot/starpilot/galaxy/tests/browser/widget-layers.cjs @@ -71,6 +71,7 @@ const projection = JSON.parse(execFileSync(process.env.PYTHON || 'python3', ['-c await page.emulateMedia({reducedMotion:'reduce'}) await page.setViewportSize({width:390,height:844}) await rows.first().evaluate(row => row.scrollIntoView({block:'center'})) + await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(resolve))))) const touchRows = await rows.evaluateAll(elements => { const top = document.querySelector('.gx-layout__sections').getBoundingClientRect().bottom return elements.filter(row => row.getBoundingClientRect().top > top && row.getBoundingClientRect().bottom < innerHeight) @@ -176,9 +177,11 @@ const projection = JSON.parse(execFileSync(process.env.PYTHON || 'python3', ['-c const saveButton = page.getByRole('button', {name:'Save changes', exact:true}) assert.equal(await saveButton.isVisible(), true) assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true) + await page.evaluate(() => window.editor.deselectWidget()) await page.getByRole('button', {name:/^Edit(?: widget)?$/}).click() assert.equal(await page.getByRole('combobox', {name:/^Selected widget/}).isVisible(), true) assert.equal(await page.getByLabel('X', {exact:true}).isVisible(), true) + if (width <= 768) assert.equal(await page.locator('.gx-layout__edit').evaluate(el => getComputedStyle(el).gap), '8px') assert.equal(await page.locator('svg.gx-layout__preview .gx-layout__remove').count(), 0) await page.getByRole('button', {name:'Widgets', exact:true}).click() await rows.filter({has:page.locator('.gx-layout__remove')}).first().locator('.gx-layout__remove').click() diff --git a/openpilot/starpilot/galaxy/tests/test_edit_panel_reveal.mjs b/openpilot/starpilot/galaxy/tests/test_edit_panel_reveal.mjs index 20d596d56b..78ce53241b 100644 --- a/openpilot/starpilot/galaxy/tests/test_edit_panel_reveal.mjs +++ b/openpilot/starpilot/galaxy/tests/test_edit_panel_reveal.mjs @@ -38,5 +38,20 @@ scrolls.length = 0 openEditPanel.call(editor(700, "static")) assert.deepEqual(scrolls, [], "wide screens without pinned tabs never scroll") +const unselected = editor(108) +unselected.activeWidgets = [{ id: "current_speed" }] +openEditPanel.call(unselected) +assert.equal(unselected.state.selected, "current_speed", "Edit restores a widget after deselection") + +let delayedAlign +globalThis.setTimeout = (fn) => { delayedAlign = fn } +const switched = editor(500) +openEditPanel.call(switched) +switched.state.inspectorPanel = "widgets" +scrolled = 0 +scrolls.length = 0 +delayedAlign() +assert.deepEqual(scrolls, [], "a delayed alignment leaves the Widgets scroll position alone") + assert.match(ONROAD_LAYOUT_TEMPLATE, /@click="openEditPanel\(\)">Edit/) globalThis.setTimeout = realTimeout diff --git a/openpilot/starpilot/galaxy/web/css/settings.css b/openpilot/starpilot/galaxy/web/css/settings.css index e03ab1e9ac..3d92dd9f8d 100644 --- a/openpilot/starpilot/galaxy/web/css/settings.css +++ b/openpilot/starpilot/galaxy/web/css/settings.css @@ -712,10 +712,10 @@ input[type="range"].gx-slider:active::-moz-range-thumb { margin: -14px -14px 0; padding: 10px 14px; background: var(--layout-solid); border-bottom: 1px solid var(--glass-border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; } .gx-layout__widget-list { gap: 6px; } .gx-layout__layer { padding: 2px; } - /* Scrolled down, the pinned preview shrinks to leave more room for the widget list. */ + /* Shrink the pinned preview while scrolling. */ .gx-layout__preview-card .gx-layout__preview { transition: max-width 180ms ease; } .gx-layout.is-shrunk .gx-layout__preview-card .gx-layout__preview { max-width: min(72%, calc(var(--layout-pin-max) * .72 * var(--layout-ratio, 2))); } - /* Keeps the page height steady so the shrink never pulls the scroll back to the top. */ + /* Preserve scroll space while the preview shrinks. */ .gx-layout.is-shrunk .gx-layout__workspace { padding-bottom: calc(var(--layout-pin-h, 0px) * .4); } .gx-layout.is-shrunk .gx-layout__scene-note { display: none; } .gx-layout.is-shrunk .gx-layout__preview-bar .gx-field { min-height: 34px; } @@ -780,7 +780,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { /* Narrow editors keep each widget's Edit controls compact so less scrolling is needed. */ @container (max-width: 1040px) { - .gx-layout__edit { gap: 8px; } + .gx-layout__inspector .gx-layout__edit { gap: 8px; } .gx-layout__inspector .gx-select.gx-field { padding-block: 0; } .gx-layout__edit .gx-row { min-height: 48px; padding: 6px 12px; } .gx-layout__edit .gx-layout__coordinates { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 8px; row-gap: 6px; } diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout.js b/openpilot/starpilot/galaxy/web/js/onroad-layout.js index 98daff822c..035b757dab 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout.js @@ -55,7 +55,7 @@ let makerPagesOpen = 0 // Screen pixels a pointer may wobble before a press on a preview widget becomes a drag. const DRAG_SLOP = 6 const CAMERA_IDS = ["pip_left", "pip_right"] -// A finger on a widget that is not armed waits this long before it grabs, so swipes scroll past. +// Let swipes scroll before an unarmed widget grabs. const HOLD_MS = 220 export class OnroadLayoutFeed { @@ -568,7 +568,7 @@ export const OnroadLayoutPage = { .slice().reverse().map(id => this.widgets.find(widget => widget.id === id)).filter(widget => widget && this.layout[widget.id].enabled) }, cameraIds() { return CAMERA_IDS.filter(id => Object.hasOwn(this.profile?.widgets || {}, id)) }, - // Side cameras in the unbroken run of front slots, under only the always-frontmost controls. + // Cameras directly below the frontmost controls. camerasOnTop() { const order = orderedWidgetIds(this.state.draft, this.state.data.metadata, this.state.profile) .filter(id => !this.profile.widgets[id]?.frontmost) @@ -576,7 +576,6 @@ export const OnroadLayoutPage = { for (let index = order.length - 1; index >= 0 && this.cameraIds.includes(order[index]); index--) top.push(order[index]) return top }, - // Each side camera locks on its own; a locked one stays in front of every unlocked widget. lockedCameraIds() { return this.camerasOnTop.filter(id => !this.state.pipUnlocked[id]) }, listWidgets() { return this.state.layerDrag ? this.state.layerDrag.rows.map(id => this.widgets.find(widget => widget.id === id)) : this.layerWidgets }, selectionBox() { @@ -692,7 +691,8 @@ export const OnroadLayoutPage = { this.observePinned() this._onOutsideClick = (event) => { const target = event.target - if (!target?.closest || target.closest(".gx-layout__workspace, .gx-select-menu, [role='listbox'], [role='dialog'], dialog, .gx-dialog")) return + if (event.composedPath().includes(this.$el) || !target?.closest || + target.closest(".gx-select-menu, [role='listbox'], [role='dialog'], dialog, .gx-dialog")) return this.deselectWidget() } document.addEventListener("click", this._onOutsideClick) @@ -776,6 +776,7 @@ export const OnroadLayoutPage = { if (!event.target?.closest?.(".gx-layout__widget")) this.deselectWidget() }, openEditPanel() { + if (this.state.selected == null) this.state.selected = this.activeWidgets?.[0]?.id || this.widgets?.[0]?.id || null this.state.inspectorPanel = "edit" this.revealEditPanel() }, @@ -783,6 +784,7 @@ export const OnroadLayoutPage = { revealEditPanel() { if (typeof window === "undefined") return const align = () => { + if (this.state.inspectorPanel !== "edit") return const tabs = this.$refs.sections, panel = this.$refs.editPanel if (!tabs || !panel || getComputedStyle(tabs).position !== "sticky") return const gap = panel.getBoundingClientRect().top - tabs.getBoundingClientRect().bottom - 8 @@ -1256,7 +1258,7 @@ export const OnroadLayoutPage = { startDrag(id, event, fromTray = false) { if (!this.editable || event.button > 0 || this.state.drag || !Object.hasOwn(this.profile.widgets, id)) return if (fromTray && this.profile.widgets[id].available === false) return - // Soft lock: a finger grabs only an armed widget at once; others need a tap first or a short hold. + // Unarmed widgets need a tap or hold before dragging. if (event.pointerType === "touch" && !fromTray && this.state.touchArmed !== id) { this.clearPendingTouch() this._pendingTouch = { id, pointerId: event.pointerId, pointerType: "touch", clientX: event.clientX, clientY: event.clientY }