Skip to content
22 changes: 22 additions & 0 deletions desktop/internal/logwindow/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ func TestTableSelectionFollowsAJumpAndTheModel(t *testing.T) {
}
}

// A jump to a distant log row must paint that row in the same driver frame
// as the ScrollIntoView request; an extra mouse movement must not be required.
func TestTableJumpToDistantRowPaintsOnTheFirstFrame(t *testing.T) {
fixture, w, driver := bigFixture(t, 200)
m := fixture.model
target := 147
m.jump(m.records[target].EpochMs)
w.inv.Invalidate()
if err := driver.Pump(); err != nil {
t.Fatal(err)
}
if !w.table.chosen.Has(m.keyBase + target) {
t.Fatalf("jump did not select record %d", target)
}
for _, hit := range tableRowHits(driver) {
if hit.Selected && hit.Bounds.Height > 0 {
return
}
}
t.Fatal("selected distant log row was not painted on the scroll request frame")
}

func TestTableRightClickChoosesTheRowAndOpensItsMenu(t *testing.T) {
fixture, w, driver := bigFixture(t, 200)
row := tableRowHits(driver)[3]
Expand Down
37 changes: 37 additions & 0 deletions desktop/internal/settingswindow/marketplace_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/marketplace"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
)

// primaryModifier is the platform's command key.
Expand Down Expand Up @@ -232,6 +233,42 @@ func TestMarketplaceWindowLoadsAndVirtualizes(t *testing.T) {
}
}

// ScrollTo must apply in the same frame that requests it; the former Viva
// List bug could leave all requested rows beyond the old viewport until a
// pointer move caused another paint (#1820).
func TestMarketplaceScrollToTopPaintsTheFirstRowImmediately(t *testing.T) {
plugins := make([]core.MarketplacePlugin, 120)
for i := range plugins {
plugins[i] = core.MarketplacePlugin{
ID: fmt.Sprintf("plugin-%03d", i), Name: fmt.Sprintf("Plugin %d", i),
LatestVersion: "1.0",
}
}
w := newWindow(NewController(Options{
Marketplace: func(context.Context) (marketplace.Snapshot, error) {
return marketplace.Snapshot{Index: core.MarketplaceIndex{Plugins: plugins}}, nil
},
}), Values{})
w.sess.page = pagePlugins
w.pluginTab = pluginTabMarketplace
d := openWindow(t, w)
d.until("the catalog", func() bool { return w.market.status == marketReady })
start := d.pluginRows()[1]
x, y := start.Bounds.X+start.Bounds.Width/2, start.Bounds.Y+start.Bounds.Height/2
if err := d.driver.Scroll(gfx.ScrollEvent{X: x, Y: y, DeltaY: 2000, Precise: true}); err != nil {
t.Fatal(err)
}
if _, visible := d.pluginRows()[0]; visible {
t.Fatal("scrolling did not leave the initial viewport")
}
w.market.list.ScrollTo(0, ui.ListStart)
w.inv.Invalidate()
d.pump()
if row, ok := d.pluginRows()[0]; !ok || row.Bounds.Height <= 0 {
t.Fatal("scroll-to-top did not paint the first row on the requested frame")
}
}

// textContaining reports whether a label of the frame contains part.
func (d *windowDriver) textContaining(part string) bool {
for _, label := range d.driver.Snapshot().Labels {
Expand Down
45 changes: 45 additions & 0 deletions desktop/internal/workbench/filetree_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/shortcuts"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/keymap"
"github.com/vivaui/viva/ui"
)

// writeTreeFiles makes the files at the slash-separated paths under root, with the folders
Expand Down Expand Up @@ -88,6 +89,50 @@ func TestProjectTreeLocatesTheActiveFile(t *testing.T) {
}
}

// A large tree must expose the selected row after the Locate click alone, not
// after another pointer event. The Viva List ScrollTo request is applied in
// the same frame (the stale-offset regression tracked by #1820).
func TestProjectTreeLocatePaintsAnOffscreenFileAfterOneClick(t *testing.T) {
root := t.TempDir()
paths := make([]string, 96)
for i := range paths {
paths[i] = fmt.Sprintf("file-%03d.go", i)
}
writeTreeFiles(t, root, paths...)
h := newHarness(t, &testKernel{Client: core.NewClient()})
p := h.openTree(t, root)
target := filepath.Join(root, paths[len(paths)-1])
h.app.openFile(p, target)
awaitDocumentState(t, h, func() bool { return p.docs.byPath(target) != nil })
h.settle()
// Opening a document may reveal its tree node automatically; force an
// offscreen starting viewport before testing the Locate scroll itself.
p.tree.view.ScrollTo(0, ui.ListStart)
h.app.invalidator.Invalidate()
if err := h.driver.Pump(); err != nil {
t.Fatal(err)
}
for _, hit := range h.driver.Snapshot().Hits {
if hit.Label == "file-095.go" && !hit.IsLabel && h.treeRowOwned(hit.ID) {
t.Fatal("the target row was already visible before Locate")
}
}

locate := h.treeAction(treeActionLocate)
if locate.Disabled {
t.Fatal("Locate is unavailable for the active file")
}
h.click(center(locate.Bounds))
if p.tree.selected == nil || p.tree.selected.path != paths[len(paths)-1] {
t.Fatalf("Locate selected %+v, want %s", p.tree.selected, paths[len(paths)-1])
}
// treeRowHit reads the last completed paint. A stale List scroll offset would
// leave this offscreen hit absent until another frame or mouse movement.
if hit := h.treeRowHit("file-095.go"); hit.Bounds.Height <= 0 {
t.Fatalf("Locate did not paint the requested row: %+v", hit)
}
}

func TestProjectTreeLocateGivesUpOnAFileThatIsGone(t *testing.T) {
h := newHarness(t, &testKernel{Client: core.NewClient()})
locateMissingTreeFile(t, h)
Expand Down
35 changes: 35 additions & 0 deletions desktop/internal/workbench/outline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package workbench

import (
"encoding/json"
"fmt"
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/vivaui/viva/ui"
)

func symbolsResult(t *testing.T, symbols ...core.DocumentSymbol) json.RawMessage {
Expand Down Expand Up @@ -66,6 +68,39 @@ func TestOutlineAsksOnceAndFollowsCaret(t *testing.T) {
}
}

// The Structure tree shares Viva's virtualized List implementation. A single
// ScrollTo request must paint a distant symbol row without another pointer
// event or a second redraw (#1820).
func TestOutlineScrollToOffscreenSymbolPaintsOnTheFirstFrame(t *testing.T) {
f := newSemanticFixture(t)
f.server.features = map[string]bool{featureDocumentSymbols: true}
f.h.app.reduceChrome(core.SetChromeOpen(itemStructure, true))
f.h.settle()
f.waitForRequests(t, 1)
outline := &f.h.app.editor.outline
// Freeze automatic caret-follow so the test owns the exact scroll request.
outline.still = true
symbols := make([]core.DocumentSymbol, 100)
for i := range symbols {
symbols[i] = symbolAt(fmt.Sprintf("entry-%03d", i), 5, 0, 1)
}
f.deliver(t, "op-1", pluginMethodDocumentSymbols, symbolsResult(t, symbols...))
if len(outline.rows) != len(symbols) {
t.Fatalf("outline has %d rows, want %d", len(outline.rows), len(symbols))
}
outline.view.ScrollTo(95, ui.ListCenter)
f.h.app.invalidator.Invalidate()
if err := f.h.driver.Pump(); err != nil {
t.Fatal(err)
}
for _, hit := range f.h.driver.Snapshot().Hits {
if hit.Label == "entry-095" && hit.Bounds.Height > 0 {
return
}
}
t.Fatal("ScrollTo did not paint the distant symbol on its requested frame")
}

func TestOutlineRowsSortAndFold(t *testing.T) {
s := &outlineState{
symbols: []core.DocumentSymbol{
Expand Down
24 changes: 24 additions & 0 deletions desktop/internal/workbench/search_everywhere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
)

func TestEverywhereFindsPagesAndOpensSelectedFile(t *testing.T) {
Expand Down Expand Up @@ -50,6 +51,29 @@ func TestEverywhereFindsPagesAndOpensSelectedFile(t *testing.T) {
if p.everywhere.cursor != nil {
t.Fatal("last page unexpectedly has a continuation")
}
// The first result is out of the virtualized viewport after loading the
// second page. Resetting the list must paint it immediately, not on a
// later mouse movement or a second Pump.
firstLabel := searchMatchLabel(p.everywhere.matches[0])
firstVisible := func() bool {
for _, hit := range h.driver.Snapshot().Hits {
if hit.Role == gfx.RoleOption && hit.Label == firstLabel && hit.Bounds.Height > 0 {
return true
}
}
return false
}
if firstVisible() {
t.Fatal("the initial global-search result remained visible at the end")
}
h.app.everywhereView.list.ScrollTo(0, ui.ListStart)
h.app.invalidator.Invalidate()
if err := h.driver.Pump(); err != nil {
t.Fatal(err)
}
if !firstVisible() {
t.Fatal("Search Everywhere ScrollTo did not paint the first result in its request frame")
}
if err := h.driver.Key(gfx.KeyEnter, 0); err != nil {
t.Fatal(err)
}
Expand Down
14 changes: 14 additions & 0 deletions desktop/internal/workbench/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/keymap"
"github.com/vivaui/viva/ui"
)

func TestProjectSearchOpensMatchingLine(t *testing.T) {
Expand Down Expand Up @@ -532,6 +533,19 @@ func TestProjectSearchVirtualizesLoadedGroups(t *testing.T) {
if h.shows(i18n.Shared(h.app.language(), "desktop.search.first200")) {
t.Fatal("obsolete total cap shown")
}
// ScrollTo must reveal the first result in the very frame it is requested.
// Before this request the first group is virtualized outside the viewport.
if h.shows("file-000.txt (1)") {
t.Fatal("scrolling to the last search results did not hide the first group")
}
h.app.searchView.list.ScrollTo(0, ui.ListStart)
h.app.invalidator.Invalidate()
if err := h.driver.Pump(); err != nil {
t.Fatal(err)
}
if !h.shows("file-000.txt (1)") {
t.Fatal("search results stayed blank at the old scroll offset until another frame")
}
}

func TestProjectSearchRejectsPathsOutsideWorkspace(t *testing.T) {
Expand Down
Loading
Loading