refactor(settings): redesign OpenCode settings with shared collapsible sections

- Replace bordered cards with compact flat rows and maintenance sections
- Add shared SettingsDisclosure for config, maintenance, and sandbox sections
- Auto-scroll expanded sections into view when outside the scrollport
- Make agent file editor and agent form full-height and keyboard-aware on mobile
This commit is contained in:
Chris Scott committed 2026-09-19 10:14:34 -04:00
1 parent 295d24ced7
commit 2a4fa956b4
18 files changed
+1013 -742

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { isSectionFullyVisible, scrollSectionIntoView } from './settingsScroll'
function buildSection(options: { sectionTop: number; sectionBottom: number; scrollerTop: number; scrollerBottom: number }) {
const scroller = document.createElement('div')
scroller.style.overflowY = 'auto'
Object.defineProperty(scroller, 'scrollHeight', { value: 1000, configurable: true })
Object.defineProperty(scroller, 'clientHeight', { value: options.scrollerBottom - options.scrollerTop, configurable: true })
scroller.getBoundingClientRect = () => ({
top: options.scrollerTop,
bottom: options.scrollerBottom,
}) as DOMRect
const section = document.createElement('div')
section.getBoundingClientRect = () => ({
top: options.sectionTop,
bottom: options.sectionBottom,
}) as DOMRect
const header = document.createElement('button')
const scrollIntoView = vi.fn()
header.scrollIntoView = scrollIntoView
section.appendChild(header)
scroller.appendChild(section)
document.body.appendChild(scroller)
return { header, scrollIntoView }
}
describe('isSectionFullyVisible', () => {
it('is true only when the section sits within the scroller bounds', () => {
expect(isSectionFullyVisible({ top: 40, bottom: 120 }, { top: 0, bottom: 400 })).toBe(true)
expect(isSectionFullyVisible({ top: 360, bottom: 520 }, { top: 0, bottom: 400 })).toBe(false)
expect(isSectionFullyVisible({ top: -120, bottom: -20 }, { top: 0, bottom: 400 })).toBe(false)
})
})
describe('scrollSectionIntoView', () => {
beforeEach(() => {
document.body.innerHTML = ''
})
it('does not scroll when the section is already fully visible', () => {
const { header, scrollIntoView } = buildSection({ sectionTop: 40, sectionBottom: 120, scrollerTop: 0, scrollerBottom: 400 })
scrollSectionIntoView(header)
expect(scrollIntoView).not.toHaveBeenCalled()
})
it('scrolls the header to the top when the section bottom is below the scroll container', () => {
const { header, scrollIntoView } = buildSection({ sectionTop: 360, sectionBottom: 520, scrollerTop: 0, scrollerBottom: 400 })
scrollSectionIntoView(header)
expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth', block: 'start' })
})
it('scrolls the header to the top when the section is above the scroll container', () => {
const { header, scrollIntoView } = buildSection({ sectionTop: -120, sectionBottom: -20, scrollerTop: 0, scrollerBottom: 400 })
scrollSectionIntoView(header)
expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth', block: 'start' })
})
it('ignores a missing header', () => {
expect(() => scrollSectionIntoView(null)).not.toThrow()
})
})
+31
View File
@@ -0,0 +1,31 @@
interface RectLike {
top: number
bottom: number
}
export function isSectionFullyVisible(section: RectLike, scroller: RectLike): boolean {
return section.top >= scroller.top && section.bottom <= scroller.bottom
}
function findScrollContainer(element: HTMLElement): HTMLElement | null {
let node = element.parentElement
while (node) {
const { overflowY } = getComputedStyle(node)
if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight) {
return node
}
node = node.parentElement
}
return null
}
export function scrollSectionIntoView(header: HTMLElement | null) {
if (!header) return
const section = header.parentElement
if (!section) return
const scroller = findScrollContainer(section)
if (scroller && isSectionFullyVisible(section.getBoundingClientRect(), scroller.getBoundingClientRect())) {
return
}
header.scrollIntoView({ behavior: 'smooth', block: 'start' })
}