diff --git a/README.md b/README.md index c382295..db1df3f 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ every native target Go ships. | Input | `Entry`, `TextView` (and so `CodeEditor`) + `Selection` + IME preview + `textinput.Client` (`github.com/go-widgets/textinput`: UTF-16 offsets, marked-text composition, `ReplaceInput`, `InputRect`) + optional `Highlighter` (syntax spans) + `ShowLineNumbers` gutter + size-to-content (`NoVerticalScroll` lays out every line, keeps the horizontal bar; `PreferredHeight()` is an `Observable[int]` following lines, font and width), `SpinButton`, `Scale`, `RangeSlider`, `SearchEntry`, `TagField`, `ComboBox`, `FormField`, `Validate`/`Rule` | | Terminal | `Terminal` (an xterm-subset emulator over the pure-Go `vt.Screen` model: cursor movement, erase, insert/delete, scroll regions, SGR 16/256/truecolor, bounded scrollback, selection + copy/paste, key encoding, `ClaimsKey` for hosts with global shortcuts, `SetFont` + `SetCellSize` (pin a cell box such as 16x16 and an OpenType face; the grid is refitted and `OnResize` fires, like `TerminalView.SetCellSize`); safe for untrusted output — no reply channel, every OSC/DCS/APC string discarded, so no clipboard write, no links, no title, no reports; parser fuzzed), `TerminalView` (Cols×Rows `TermCell` grid, block cursor, wrap/scroll, per-cell FG/BG) | | Selection | `ListBox`, `TreeView`, `DropDown` | -| Containers | `Container` + swappable `Layout` (`FitLayout`, `BoxLayout`, `BorderLayout`, `CardLayout`, `FlowLayout`); convenience wrappers `HBox`, `VBox`, `Grid`, `Frame`, `Dock`, `Border`, `Stack`, `Overlay`, `Paned`, `Splitter` (N panes with draggable, focusable dividers after the WAI-ARIA window-splitter pattern: fixed panes sized by an `mvvm.Observable`, flexible ones by weight, min/max, collapse on double-click, Enter or a drag to the minimum, arrows/Home/End/Enter, 3:1 divider and focus ring, resize cursor; panes close and reopen through `Open(i)`, an `mvvm.Observable`, the last `Essential` pane refusing, with `ClosablePane` for a titled header and a close button), `Expander`, `Accordion`; declarative `Node` builder + `ViewController` (`LookupAs`) | +| Containers | `Container` + swappable `Layout` (`FitLayout`, `BoxLayout`, `BorderLayout`, `CardLayout`, `FlowLayout`); convenience wrappers `HBox`, `VBox`, `Grid`, `Frame`, `Dock`, `Border`, `Stack`, `Overlay`, `Paned`, `Splitter` (N panes with draggable, focusable dividers after the WAI-ARIA window-splitter pattern: fixed panes sized by an `mvvm.Observable`, flexible ones by weight, min/max, collapse on double-click, Enter or a drag to the minimum, a `Default` size or weight a double-click restores on a divider with nothing to collapse, arrows/Home/End/Enter, 3:1 divider and focus ring, resize cursor; panes close and reopen through `Open(i)`, an `mvvm.Observable`, the last `Essential` pane refusing, with `ClosablePane` for a titled header and a close button), `Expander`, `Accordion`; declarative `Node` builder + `ViewController` (`LookupAs`) | | Tabs | `Notebook`, `ViewSwitcher`, `Carousel` | | Scroll | `ScrollView`, `Scrollbar` | | Feedback | `ProgressBar`, `ProgressCircle`, `LevelBar`, `Spinner`, `Image`, `Tooltip`, `Notification`, `Toast`, `Banner`, `Alert`, `Badge`, `LoadMask`, `Backdrop`, `FocusRing` | diff --git a/splitter.go b/splitter.go index 8ce5209..542d3f0 100644 --- a/splitter.go +++ b/splitter.go @@ -90,6 +90,11 @@ type SplitPane struct { // of an IDE: either may be closed, not both); when none is, at least one pane // of any kind stays on. See [Splitter.CanClose]. Essential bool + // Default, when above 0, is the Size (fixed pane) or Weight (flexible pane) + // a double-click on a divider next to this pane puts back, for a divider + // that has no collapsible pane to toggle: the "reset the split" gesture. A + // pair of flexible panes with Defaults 55 and 45 returns to 55 / 45. + Default int restore int // the logical size before the pane was collapsed } @@ -717,7 +722,11 @@ func (s *Splitter) press(j, main int, double bool) { if double || (s.lastDiv == j && now.Sub(s.lastAt) < splitterDoubleClick) { s.lastDiv = -1 before := append([]int(nil), s.px...) - s.toggle(j) + if s.control(s.handles[j]) < 0 { + s.reset(j) + } else { + s.toggle(j) + } s.fire(before) return } @@ -727,6 +736,25 @@ func (s *Splitter) press(j, main int, double bool) { s.dragging.Set(true) } +// reset puts the two panes around divider j back to their Default size or +// weight (those without one keep theirs), laying out once. +func (s *Splitter) reset(j int) { + h := s.handles[j] + s.batch = true + for _, i := range []int{h.a, h.b} { + p := s.panes[i] + switch { + case p.Default <= 0: + case p.Size != nil: + p.Size.Set(p.Default) // the layout holds it between Min and Max + default: + p.Weight.Set(p.Default) + } + } + s.batch = false + s.layout() +} + // control is the pane divider j's collapse acts on: the fixed collapsible one // before it, else after it; -1 if neither is. func (s *Splitter) control(h *dividerHandle) int { diff --git a/splitter_default_test.go b/splitter_default_test.go new file mode 100644 index 0000000..873fb9d --- /dev/null +++ b/splitter_default_test.go @@ -0,0 +1,72 @@ +// Copyright (c) 2026 the wasmdesk/toolkit authors. All rights reserved. +// Use of this source code is governed by a BSD-3-Clause license that can be +// found in the LICENSE file at the root of this repository. + +package toolkit + +import "testing" + +func (d *ide) double(t *testing.T, j int) { + t.Helper() + r, ok := d.s.HandleRect(j) + if !ok { + t.Fatalf("no divider %d", j) + } + d.s.OnEvent(Event{Kind: EventClick, X: r.X + 1, Y: 10, Code: "double"}) +} + +// A double-click on a divider whose panes are flexible puts both back to their +// Default weights, and tells OnResized what moved. +func TestSplitterDoubleClickResetsFlexiblePanesToTheirDefaults(t *testing.T) { + d := newIDE(t, 1200) + d.editorPane.Default, d.prevPane.Default = 55, 45 + d.drag(t, 1, 150) + moved := d.sizes() + d.resized = nil + d.double(t, 1) + got := d.sizes() + if got == moved { + t.Fatalf("the double-click changed nothing: %v", got) + } + if got[1]*45 < got[2]*55-55 || got[1]*45 > got[2]*55+55 { + t.Fatalf("editor/preview = %d/%d, want 55:45", got[1], got[2]) + } + if len(d.resized) != 1 { + t.Fatalf("OnResized calls = %v, want one", d.resized) + } + // already at the default: nothing moves, nothing is reported + d.resized = nil + d.double(t, 1) + if d.sizes() != got || len(d.resized) != 0 { + t.Fatalf("a reset at the default moved %v or reported %v", d.sizes(), d.resized) + } +} + +// A fixed pane returns to its Default size; a pane with no Default is left as +// it is. +func TestSplitterDoubleClickResetsAFixedPaneAndLeavesTheOneWithoutDefault(t *testing.T) { + d := newIDE(t, 1200) + d.helpPane.Default = 300 + d.drag(t, 2, -60) + if d.help.Get() == 300 { + t.Fatal("the drag did not move Help") + } + prev := d.preview.Get() + d.double(t, 2) + if d.help.Get() != 300 { + t.Fatalf("Help = %d, want 300", d.help.Get()) + } + if d.helpPane.Size != d.help || d.preview.Get() == 0 || prev == 0 { + t.Fatal("setup") + } +} + +// A divider next to a collapsible pane keeps toggling it, whatever the Defaults. +func TestSplitterDoubleClickStillCollapsesWhenThePaneCan(t *testing.T) { + d := newIDE(t, 1200) + d.filesPane.Default, d.editorPane.Default = 300, 1 + d.double(t, 0) + if !d.s.Collapsed(0) { + t.Fatal("a collapsible pane's divider must keep collapsing") + } +}