Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions desktop/internal/settingswindow/installed_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,14 @@ func TestRepositoriesDialogAddsAndRemovesAnIndex(t *testing.T) {
}
}

// A plugin's Settings tab grows its form to the height under the tab bar, so the settings list
// fills it and shows its last row whole, rather than sitting at a fixed height in the scroll.
func TestInstalledSettingsTabListFillsTheDetail(t *testing.T) {
// A plugin's Settings tab has no scroll of its own: its rows scroll with the detail they sit
// in, so the wheel over them carries the detail from the first row to the last, both whole.
func TestInstalledSettingsTabFormScrollsWithTheDetail(t *testing.T) {
const count = 30
manifest := flagsManifest(t, count)
facts := []PluginFacts{{ID: "dev.example.settings", Name: "Settings", Vendor: "Example", Version: "1.0.0", Source: PluginSourceDisk, Settings: count}}
fits := map[int]settingsListFit{}
for _, height := range settingsListHeights {
gaps := map[int]float32{}
for _, height := range settingsFormHeights {
client := core.NewClient()
source := settingsFormSource{store: pluginsettings.New(client, t.TempDir()), manifest: manifest, workspace: t.TempDir()}
w := newWindow(NewController(Options{
Expand All @@ -631,7 +631,7 @@ func TestInstalledSettingsTabListFillsTheDetail(t *testing.T) {
d.until("the form", func() bool { return w.pluginSettings != nil && w.pluginSettings.loaded && !w.pluginSettings.running })
w.inv.Invalidate()
d.pump()
fits[height] = measureSettingsList(t, d, w, fmt.Sprintf("Flag %02d", count-1))
gaps[height] = measureSettingsForm(t, d, w, "Flag 00", fmt.Sprintf("Flag %02d", count-1))
}
checkSettingsListFills(t, fits)
checkSettingsFormEnds(t, gaps)
}
3 changes: 0 additions & 3 deletions desktop/internal/settingswindow/plugin_settings_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ type pluginSettingsForm struct {
scope int
editor pluginservice.SettingsEditor
controls [2][]pluginSettingControl
// rows is the form's list of rows, which declares only the ones on screen.
rows ui.ListState
}

func newPluginSettingsForm(loader PluginSettingsLoader) *pluginSettingsForm {
Expand All @@ -123,7 +121,6 @@ func newPluginSettingsForm(loader PluginSettingsLoader) *pluginSettingsForm {
})
p.opEffect = ui.NewEffect[pluginSettingsResult, int](p.runOp)
}
p.rows.Key = nil
return p
}

Expand Down
57 changes: 26 additions & 31 deletions desktop/internal/settingswindow/plugin_settings_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import (
"github.com/vivaui/viva/ui"
)

// settingsListMinHeight is the least height of a form's settings list: a window too short to
// give it that scrolls the page instead of squeezing the list. It still fits whole under an
// installed plugin's header and tabs in the smallest window.
const settingsListMinHeight = 160

// scopeChoices are the two scopes a plugin's settings are edited in: global, then project.
var scopeChoices = []int{0, 1}

Expand All @@ -36,11 +31,12 @@ func (w *window) scopeLabel(scope int) string {
// above the toolbar, which parts the form from what its parent shows above it; a page that
// opens on the form leaves it out.
//
// The panel grows into the height its parent leaves under what sits above it, and the rows'
// list fills what the panel's header leaves, so the last row ends at the bottom of the page
// and not at a fixed height above blank space. The list keeps settingsListMinHeight, so the
// parent must be a scroll that grows its content to the viewport: a short window scrolls
// the page rather than cutting the list's last rows off under the window's buttons.
// The panel has no scroll of its own: its header, the plugin's region and all of its rows
// are declared whole and scroll with the page its parent scrolls. Core caps a page at
// MAX_SETTINGS settings and MAX_SETTING_ACTIONS actions, so the rows of one form are a short
// form, which the project's scrolling rules let a view declare without virtualizing it. A
// scroll of the panel's own would take only the height a tall region leaves it, scroll inside
// that height once the page is at its end, and cut its first rows off under the region.
func (w *window) pluginSettingsPanel(c ui.C, id string, ruled bool) {
if !w.selectPluginForm(id) {
ui.Wrap(c, i18n.Shared(w.marketLanguage(), "desktop.pluginSettings.draftLimit")).Color(w.pal.danger)
Expand Down Expand Up @@ -176,30 +172,29 @@ func (w *window) pluginSettingsPanel(c ui.C, id string, ruled bool) {
return
}
// Core's section references are walked in Core's order, without sorting or
// regrouping them; the list declares only the rows in its viewport.
ui.List(c, &p.rows, len(p.layout), func(row ui.ListRow) {
w.pluginSettingsListRow(row, p, source != "")
}).Scrollbars().FillWidth().Grow(1).MinHeight(settingsListMinHeight).Label(i18n.Shared(language, "desktop.pluginSettings.title"))
// regrouping them. The rows hold their own vertical padding, so they sit in a
// column of their own rather than taking the gap the panel parts its header with.
ui.Column(c.Part("rows")).FillWidth().Shrink(0).Children(func() {
for index := range p.layout {
w.pluginSettingsFormRow(c.KeyInt(index), p.layout[index], source != "")
}
})
})
}

// pluginSettingsListRow declares one row of the form's list: a section title, a setting
// or an action.
func (w *window) pluginSettingsListRow(row ui.ListRow, p *pluginSettingsForm, hasSource bool) {
c := row.C
item := p.layout[row.Index]
row.Element.FillWidth().Children(func() {
switch {
case item.action:
w.pluginSettingActionRow(c, item.row)
case item.row < 0:
ui.Row(c).FillWidth().Height(28).Items(ui.Center).Children(func() {
ui.Text(c, item.title).FontSize(13).Weight(gfx.WeightSemibold).Color(w.pal.text)
})
default:
w.pluginSettingRow(c, item.row, hasSource)
}
})
// pluginSettingsFormRow declares one row of the form: a section title, a setting or an
// action.
func (w *window) pluginSettingsFormRow(c ui.C, item pluginSettingLayout, hasSource bool) {
switch {
case item.action:
w.pluginSettingActionRow(c, item.row)
case item.row < 0:
ui.Row(c).FillWidth().Shrink(0).Height(28).Items(ui.Center).Children(func() {
ui.Text(c, item.title).FontSize(13).Weight(gfx.WeightSemibold).Color(w.pal.text)
})
default:
w.pluginSettingRow(c, item.row, hasSource)
}
}

// readOnlyField shows value as a field that cannot be edited. Box.Disabled does not apply to
Expand Down
139 changes: 74 additions & 65 deletions desktop/internal/settingswindow/settings_surfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
)

func TestSettingsDynamicPagesShareDraftsFilterActionsAndRefreshCleanForms(t *testing.T) {
Expand Down Expand Up @@ -211,91 +210,101 @@ func flagsManifest(t *testing.T, count int) json.RawMessage {
return manifest
}

// settingsListFit is where a form's settings list sits in the window once the page is
// scrolled to its end: its visible height and the distance from its bottom to the top of the
// window's OK button.
type settingsListFit struct{ height, gap float32 }

// settingsListHits are the open form's settings list, as much of it as is visible, and the
// window's OK button.
func settingsListHits(t *testing.T, d *windowDriver, w *window) (list, ok gfx.Hit) {
// settingsOKButton is the window's OK button.
func settingsOKButton(t *testing.T, d *windowDriver, w *window) gfx.Hit {
t.Helper()
for _, hit := range d.driver.Snapshot().Hits {
switch {
case hit.Role == gfx.RoleListBox && hit.Label == i18n.Shared(i18n.English, "desktop.pluginSettings.title"):
list = hit
case hit.Role == gfx.RoleButton && hit.Label == w.text.Settings.OK:
ok = hit
if hit.Role == gfx.RoleButton && hit.Label == w.text.Settings.OK {
return hit
}
}
if list.Bounds.Height == 0 || ok.Bounds.Height == 0 {
t.Fatal("no settings list or no OK button")
}
return list, ok
t.Fatal("no OK button")
return gfx.Hit{}
}

// measureSettingsList scrolls the page to its end, measures the open form's list, then
// scrolls the list to its last row and fails unless that row is drawn whole inside it.
func measureSettingsList(t *testing.T, d *windowDriver, w *window, last string) settingsListFit {
// settingsRowLabel is the drawn title of the form row whose words are value. It fails unless
// the row is drawn and nothing cuts it from above or below, which a scroll of the form's own
// would once the page is at its end.
func settingsRowLabel(t *testing.T, d *windowDriver, value string) app.Label {
t.Helper()
list, _ := settingsListHits(t, d, w)
// The wheel turns just above the list, so it scrolls the page and not the list's rows.
if err := d.driver.Scroll(gfx.ScrollEvent{X: list.Bounds.X + list.Bounds.Width/2, Y: list.Bounds.Y - 4, DeltaY: 10000, Precise: true}); err != nil {
t.Fatal(err)
}
d.pump()
list, ok := settingsListHits(t, d, w)
bottom := list.Bounds.Y + list.Bounds.Height
w.pluginSettings.rows.ScrollTo(len(w.pluginSettings.layout)-1, ui.ListEnd)
w.inv.Invalidate()
d.pump()
d.pump()
found := false
for _, label := range d.driver.Snapshot().Labels {
if label.Value != last {
if label.Value != value {
continue
}
found = true
if label.Bounds.Y < list.Bounds.Y || label.Bounds.Y+label.Bounds.Height > bottom {
t.Fatalf("the last row %+v is cut by the list %+v", label.Bounds, list.Bounds)
if label.Clipped && (label.Bounds.Y < label.Clip.Y-0.5 || label.Bounds.Y+label.Bounds.Height > label.Clip.Y+label.Clip.Height+0.5) {
t.Fatalf("the row %q at %+v is cut by %+v", value, label.Bounds, label.Clip)
}
return label
}
if !found {
t.Fatalf("the last row %q is not drawn", last)
}
return settingsListFit{height: list.Bounds.Height, gap: ok.Bounds.Y - bottom}
t.Fatalf("the row %q is not drawn", value)
return app.Label{}
}

// settingsListHeights are the window heights the list is measured in: the smallest window,
// which scrolls the page to show the list's least height, and two that it fills.
var settingsListHeights = [3]int{windowMinHeight, 800, 1000}
// wheelOverSettingsRow turns the wheel by delta over a form row, where a scroll of the form's
// own would take the wheel instead of passing it to the page.
func wheelOverSettingsRow(t *testing.T, d *windowDriver, row app.Label, delta float32) {
t.Helper()
at := row.Bounds
if err := d.driver.Scroll(gfx.ScrollEvent{X: at.X + at.Width/2, Y: at.Y + at.Height/2, DeltaY: delta, Precise: true}); err != nil {
t.Fatal(err)
}
d.pump()
}

// checkSettingsListFills fails unless, in the two taller windows, the list grew by exactly what
// the window grew and ends the same short distance above the window's buttons, and, in the
// smallest, the page scrolls to the whole of the list's least height above the buttons.
func checkSettingsListFills(t *testing.T, fits map[int]settingsListFit) {
// measureSettingsForm fails unless the form has no scroll of its own and the wheel over its
// rows carries the page from its first row to its last, both drawn whole. It returns the
// distance from the last row's bottom to the top of the window's OK button, which says the
// page stops at the end of its content rather than at a height the form chose.
func measureSettingsForm(t *testing.T, d *windowDriver, w *window, first, last string) float32 {
t.Helper()
small, mid, tall := fits[settingsListHeights[0]], fits[settingsListHeights[1]], fits[settingsListHeights[2]]
grown := float32(settingsListHeights[2] - settingsListHeights[1])
if delta := tall.height - mid.height; delta < grown-1 || delta > grown+1 {
t.Fatalf("the list grew %v for a window %v taller: %+v, %+v", delta, grown, mid, tall)
title := i18n.Shared(i18n.English, "desktop.pluginSettings.title")
for _, hit := range d.driver.Snapshot().Hits {
if hit.Role == gfx.RoleListBox && hit.Label == title {
t.Fatalf("the form declares a scroll of its own at %+v", hit.Bounds)
}
}
if tall.gap-mid.gap > 1 || mid.gap-tall.gap > 1 || mid.gap < 0 || tall.gap > 3*contentPad {
t.Fatalf("the list does not end at the page's bottom: %+v, %+v", mid, tall)
wheelOverSettingsRow(t, d, settingsRowLabel(t, d, first), 10000)
row := settingsRowLabel(t, d, last)
ok := settingsOKButton(t, d, w)
bottom := row.Bounds.Y + row.Bounds.Height
if bottom > ok.Bounds.Y {
t.Fatalf("the last row at %+v is under the window's buttons at %v", row.Bounds, ok.Bounds.Y)
}
// The wheel back up over the rows brings the first row back, whole.
wheelOverSettingsRow(t, d, row, -10000)
settingsRowLabel(t, d, first)
return ok.Bounds.Y - bottom
}

// settingsFormHeights are the window heights the form is measured in: the smallest window and
// two taller ones, all of them shorter than the 30 rows the form holds.
var settingsFormHeights = [3]int{windowMinHeight, 800, 1000}

// checkSettingsFormEnds fails unless the page ends the same short distance under the form's
// last row whatever the window's height. The form scrolls with the page, so the page's end is
// the end of the form's rows and not a height the form kept for itself.
func checkSettingsFormEnds(t *testing.T, gaps map[int]float32) {
t.Helper()
small, mid, tall := gaps[settingsFormHeights[0]], gaps[settingsFormHeights[1]], gaps[settingsFormHeights[2]]
for _, gap := range [3]float32{small, mid, tall} {
if gap < 0 || gap > 3*contentPad {
t.Fatalf("the page does not end under the last row: %v, %v, %v", small, mid, tall)
}
}
if small.height < settingsListMinHeight-1 || small.gap < 0 {
t.Fatalf("the smallest window shows %+v of the list", small)
if tall-mid > 1 || mid-tall > 1 || mid-small > 1 || small-mid > 1 {
t.Fatalf("the page's end moved with the window's height: %v, %v, %v", small, mid, tall)
}
}

// A language page's settings list fills the page under the form's header, so the last row ends
// at the page's bottom instead of being cut off at a fixed height above blank space, and a
// window too short for the list scrolls the page.
func TestSettingsDynamicPageListFillsThePageAndShowsItsLastRowWhole(t *testing.T) {
// A language page's form scrolls with the page it sits in, so the wheel over its rows carries
// the page from the first row to the last with both drawn whole, whatever the window's height.
// A scroll of the form's own would take only the height what sits above it leaves, and cut its
// rows off once the page itself was at its end.
func TestSettingsDynamicPageFormScrollsWithThePageAndShowsItsRowsWhole(t *testing.T) {
const count = 30
manifest := flagsManifest(t, count)
fits := map[int]settingsListFit{}
for _, height := range settingsListHeights {
gaps := map[int]float32{}
for _, height := range settingsFormHeights {
client := core.NewClient()
source := settingsFormSource{store: pluginsettings.New(client, t.TempDir()), manifest: manifest, workspace: t.TempDir()}
w := newWindow(NewController(Options{PluginSettings: source, Text: func() *i18n.Messages { return i18n.For(i18n.English) }, SettingsNavigation: client.SettingsNavigation, SettingsPages: func(ctx context.Context, _ i18n.Language) ([]core.SettingsPage, error) {
Expand All @@ -307,7 +316,7 @@ func TestSettingsDynamicPageListFillsThePageAndShowsItsLastRowWhole(t *testing.T
d.until("the form", func() bool { return w.pluginSettings != nil && w.pluginSettings.loaded && !w.pluginSettings.running })
w.inv.Invalidate()
d.pump()
fits[height] = measureSettingsList(t, d, w, fmt.Sprintf("Flag %02d", count-1))
gaps[height] = measureSettingsForm(t, d, w, "Flag 00", fmt.Sprintf("Flag %02d", count-1))
}
checkSettingsListFills(t, fits)
checkSettingsFormEnds(t, gaps)
}
8 changes: 8 additions & 0 deletions desktop/internal/settingswindow/source_settings_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ func (w *window) sourceSettingsPanel(c ui.C, p *sourceSettingsForm) {
// sourceNavWidth is the width of the module list beside a sidebar form.
const sourceNavWidth = 168

// settingsListMinHeight is the least height of a source form's rows: they are the entries of
// a tool's own configuration, which has no upper bound, so they scroll by themselves beside
// the module tree. A window too short to give them that scrolls the page instead of squeezing
// them. It still fits whole under an installed plugin's header and tabs in the smallest
// window. A plugin's own declared settings are capped by Core and are not a list; they are
// declared whole and scroll with the page.
const settingsListMinHeight = 160

func (p *sourceSettingsForm) navNode(i int) ui.TreeNode {
if i < 0 || i >= len(p.nav) {
return ui.TreeNode{}
Expand Down
16 changes: 16 additions & 0 deletions docs/assets/plugin-settings-single-scroll/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 插件设置表单只剩一层滚动

来自生产 Viva Page 的无头渲染,用的是插件契约里的 `view-panel` 示例插件(`dev.lithe.fixture.view-panel`),
配置目录是固定的假路径,不代表任何真实插件或用户数据。窗口高度 760 点,中文浅色主题,打开「插件 →
已安装 → View Panel → 设置」,再把滚轮停在右侧详情里一直向下滚到底。

| 场景 | 截图 |
| --- | --- |
| 改动前:详情滚到底之后,插件声明的设置行还在自己的小滚动区域里,最后一行「Watch files」被下边缘截断,要在这块区域里再滚一次才能看到 | [截图](plugin-settings-before-zh-light.png) |
| 改动后:效果预览和设置行一起随页面滚动,滚到底时最后一行「Watch files」完整显示,右侧只有一条滚动条 | [截图](plugin-settings-after-zh-light.png) |

「改动前」来自本次改动的父提交,用一次性的无头脚手架截取,脚手架没有提交。行为本身由
`desktop/internal/settingswindow` 的 `TestSettingsDynamicPageFormScrollsWithThePageAndShowsItsRowsWhole`
和 `TestInstalledSettingsTabFormScrollsWithTheDetail` 覆盖,这两个测试在改动前都会失败。

截图不代表 macOS、Windows 原生窗口验收。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading