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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Core 的第一次 toggle(增减一行选择)只把点击目标加入标记
- 没有批量标记和范围锚点时,Core 先把可见的、非根的当前行纳入,再切换点击行。已有批量继续只切换一行;隐藏旧行不因首次点击被意外加入。
- 文件树与 Git 分支列表有批量状态时只用批量标记呈现选中底色;取消选中的当前行不继续显示为已选。
- 文件树记录已观察的焦点,指针焦点先交给点击处理,键盘焦点仍更新当前行。窗口失焦和恢复不清除批量。焦点清空时只记录焦点变化,行匹配要求焦点 ID 非空。目录列表刚加入的行在首次绘制前也使用空 ID,两者相等会把原选中项误移到新行。
- 引用和问题树复用 `treelist.FocusedRow` 匹配 Viva 行身份,只在非空焦点命中已声明行时更新选择。焦点清空仍写入已观察状态,因此重新聚焦同一行能够响应;工具栏定位保留原来的滚动和预览行为。这个适配只解释 Viva 的焦点 ID,不改变 Core 的结果排序或业务选择规则。
- macOS Command 和 Windows Control 由 Viva 已有的主修饰键定义提供,不新增系统按键适配。

## 考虑过的备选方案
Expand All @@ -34,6 +35,7 @@ Core 的第一次 toggle(增减一行选择)只把点击目标加入标记
- Core 共享 row-selection fixture 修改后先红后绿,覆盖首次追加保留、点击当前行取消、隐藏标记、范围选择和根保护。
- `desktop/internal/workbench/filetree_test.go` 的真实驱动点击先复现旧选择丢失,修复后覆盖追加、取消、全部选中底色、普通点击清除及键盘焦点回归。
- `TestProjectTreeKeepsSelectionWhenFocusClearsBeforeNewRowsPaint` 控制焦点清空与目录行首次绘制的顺序,修复前选中新增行,修复后保留原选中行。`TestProjectTreeLocateGivesUpOnAFileThatIsGone` 覆盖删除活跃文件后定位的完整流程,`TestVisualProjectTreeMissingFile` 采集明暗主题的结果。
- `desktop/internal/workbench/result_tree_focus_test.go` 用真实 Viva Tree 定序控制引用和问题结果刷新、清空焦点、重新聚焦及方向键。新行在第一次绘制前没有行 ID,旧实现会误选它;修复后保留原行,失焦时定位不抢键盘,回到原焦点后继续更新选择。`references_visual_test.go` 与 `problems_visual_test.go` 在未声明行时清空焦点,再采集保留选择及预览的中英文明暗主题截图。
- `desktop/internal/workbench/branch_delete_test.go` 混合批量从普通点击开始,再用平台主修饰键追加,验证实际删除集合。
- 通过 `scripts/desktop/desktop-go.sh` 执行定向无头测试,`desktop/internal/workbench/branch_delete_visual_test.go` 生成中英文明暗主题的文件树多选截图。Windows 原生交互验证仍待目标平台执行。

Expand All @@ -42,4 +44,6 @@ Core 的第一次 toggle(增减一行选择)只把点击目标加入标记
- `desktop/internal/workbench/filetree.go`
- `desktop/internal/workbench/filetree_view.go`
- `desktop/internal/workbench/gitlog_view.go`
- `desktop/internal/treelist/treelist.go`
- `desktop/internal/workbench/references_view.go` 与 `desktop/internal/workbench/problems_view.go`
- 外部 Lithe-core-rust 的 `rust/crates/row-selection/src/lib.rs` 与共享 fixture。
20 changes: 18 additions & 2 deletions desktop/internal/treelist/treelist.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Package treelist holds the measures and the text color of the desktop's tree rows: the
// Package treelist holds the measures, text color and focus lookup of desktop tree rows: the
// Project tool window's tree and the lists of files in the Git tool windows share them, so
// a name looks the same wherever it is listed. The rows themselves are Viva's Tree and List.
package treelist

import "github.com/vivaui/viva/gfx"
import (
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
)

// The sizes of a row, the same in every tree list.
const (
Expand Down Expand Up @@ -39,3 +42,16 @@ func Text(dark bool) gfx.Color {
func Width(depth int, content float32) float32 {
return 2*Gutter + float32(depth*Indent) + Disclosure + Gap + content + Trailing
}

// FocusedRow finds the row whose Viva identity holds the keyboard focus. Cleared focus
// cannot match a row: a row added since the last paint can also have the zero identity.
func FocusedRow(view *ui.TreeState, count int, focused gfx.ID) (int, bool) {
if !focused.IsZero() {
for i := range count {
if view.RowID(i) == focused {
return i, true
}
}
}
return -1, false
}
12 changes: 4 additions & 8 deletions desktop/internal/workbench/problems_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,10 @@ func (a *App) syncProblemsSelection(canvas *gfx.Canvas) {
focused := canvas.Focused()
inTree := false
if focused != v.focus || v.reveal {
for i := range rows {
if v.view.RowID(i) == focused {
inTree = true
if focused != v.focus {
v.selected, v.selectedRow = rows[i].Key, i
}
break
}
i, found := treelist.FocusedRow(&v.view, len(rows), focused)
inTree = found
if found && focused != v.focus {
v.selected, v.selectedRow = rows[i].Key, i
}
v.focus = focused
}
Expand Down
15 changes: 15 additions & 0 deletions desktop/internal/workbench/problems_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/plugindiag"
"github.com/1lck/Lithe-IDEA/desktop/internal/store"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/headless"
"github.com/vivaui/viva/ui"
)

// TestVisualProblemsToolWindow captures the Problems tool window over two files' diagnostics:
Expand Down Expand Up @@ -95,6 +97,19 @@ func TestVisualProblemsToolWindow(t *testing.T) {
h.clickNamed(problemsRowNamed(t, h, problemsDiagnosticRow(t, h, "The value of the local variable count is not used")))
h.await("the diagnostic's preview", func() bool { return v.preview.view != nil && v.preview.path == service })
h.settleChain()
// A refreshed tree has yet to declare its rows when focus clears. Keep
// the chosen diagnostic and the preview captured below.
selected := v.selected
v.focus = v.view.RowID(v.selectedRow)
if v.focus.IsZero() {
t.Fatal("the selected diagnostic has no painted identity")
}
v.view = ui.TreeState{}
h.app.syncProblemsSelection(new(gfx.Canvas))
if v.selected != selected {
t.Fatalf("cleared focus selected %q, want %q", v.selected, selected)
}
h.settleChain()
if err := session.Screenshot(filepath.Join(out, "problems-project-"+look.theme+"-"+look.language+".png")); err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 4 additions & 8 deletions desktop/internal/workbench/references_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,10 @@ func (a *App) syncReferenceSelection(canvas *gfx.Canvas) {
focused := canvas.Focused()
inTree := false
if focused != s.focus || s.reveal {
for i := range s.rows {
if s.view.RowID(i) == focused {
inTree = true
if focused != s.focus {
s.selected, s.selectedRow = s.rows[i].Key, i
}
break
}
i, found := treelist.FocusedRow(&s.view, len(s.rows), focused)
inTree = found
if found && focused != s.focus {
s.selected, s.selectedRow = s.rows[i].Key, i
}
s.focus = focused
}
Expand Down
15 changes: 15 additions & 0 deletions desktop/internal/workbench/references_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/headless"
"github.com/vivaui/viva/ui"
)

// TestVisualReferencesToolWindow captures the References tool window after Find Usages on a
Expand Down Expand Up @@ -91,6 +92,20 @@ func TestVisualReferencesToolWindow(t *testing.T) {
h.settleChain()
h.await("the usage's preview", func() bool { return visualReferencesReady(h.app) })
h.settleChain()
// Keep the chosen usage while the refreshed tree has not declared any
// rows and focus clears. The screenshot must still show its preview.
s := &h.app.editor.refs
selected := s.selected
s.focus = s.view.RowID(s.selectedRow)
if s.focus.IsZero() {
t.Fatal("the selected usage has no painted identity")
}
s.view = ui.TreeState{}
h.app.syncReferenceSelection(new(gfx.Canvas))
if s.selected != selected {
t.Fatalf("cleared focus selected %q, want %q", s.selected, selected)
}
h.settleChain()
if err := session.Screenshot(filepath.Join(out, "references-"+look.theme+"-"+look.language+".png")); err != nil {
t.Fatal(err)
}
Expand Down
194 changes: 194 additions & 0 deletions desktop/internal/workbench/result_tree_focus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package workbench

import (
"testing"
"time"

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

// resultTreeFocus drives Viva's real tree and each panel's selection adapter without
// background queries: the test controls when a result arrives relative to a paint.
type resultTreeFocus struct {
view *ui.TreeState
selected *string
selectedRow *int
focus *gfx.ID
reveal *bool
sync func(*gfx.Canvas)
setRows func(...string)
row func(int) string
count func() int
driver *app.Driver
invalidator *app.Invalidator
}

func newResultTreeFocus(t *testing.T, panel string) *resultTreeFocus {
t.Helper()
a := new(App)
f := &resultTreeFocus{invalidator: new(app.Invalidator)}
switch panel {
case "references":
s := &a.editor.refs
f.view, f.selected, f.selectedRow, f.focus, f.reveal = &s.view, &s.selected, &s.selectedRow, &s.focus, &s.reveal
f.sync = a.syncReferenceSelection
f.setRows = func(keys ...string) {
s.rows = nil
for _, key := range keys {
s.rows = append(s.rows, core.ReferenceRow{Key: key})
}
}
f.row = func(i int) string { return s.rows[i].Key }
f.count = func() int { return len(s.rows) }
case "problems":
v := &a.problems
f.view, f.selected, f.selectedRow, f.focus, f.reveal = &v.view, &v.selected, &v.selectedRow, &v.focus, &v.reveal
f.sync = a.syncProblemsSelection
f.setRows = func(keys ...string) {
v.result.Rows = nil
for _, key := range keys {
v.result.Rows = append(v.result.Rows, core.ProblemsRow{Key: key})
}
}
f.row = func(i int) string { return v.result.Rows[i].Key }
f.count = func() int { return len(v.result.Rows) }
default:
t.Fatalf("unknown result tree %q", panel)
}
f.setRows("first", "original")
*f.selected, *f.selectedRow = "original", 1
f.view.Node = func(i int) ui.TreeNode { return ui.TreeNode{Selected: i == *f.selectedRow} }
f.view.RowHeight = 24
theme := ui.LightTheme()
page := ui.NewPage(ui.PageConfig{
Theme: &theme, Invalidator: f.invalidator,
View: func(c ui.C) {
f.sync(c.Canvas())
ui.Tree(c, f.view, f.count(), f.row, func(i int) { ui.Text(c, f.row(i)) }).Scrollbars().Fill()
},
})
var err error
f.driver, err = app.NewDriver(ui.Configure(page, app.Config{Width: 300, Height: 120, Invalidator: f.invalidator}), nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(f.driver.Close)
f.paint(t)
return f
}

func (f *resultTreeFocus) paint(t *testing.T) {
t.Helper()
f.invalidator.Invalidate()
if err := f.driver.Advance(20 * time.Millisecond); err != nil {
t.Fatal(err)
}
}

func (f *resultTreeFocus) wantSelection(t *testing.T, key string, row int) {
t.Helper()
if *f.selected != key || *f.selectedRow != row || f.view.Selected() != row {
t.Fatalf("selection = %q at %d (tree %d), want %q at %d", *f.selected, *f.selectedRow, f.view.Selected(), key, row)
}
}

func TestResultTreesKeepSelectionWhenFocusClearsBeforeNewRowsPaint(t *testing.T) {
for _, panel := range []string{"references", "problems"} {
t.Run(panel, func(t *testing.T) {
f := newResultTreeFocus(t, panel)
*f.focus = f.view.RowID(0)
if f.focus.IsZero() {
t.Fatal("the painted row has no identity")
}
// A result arrives before the frame that observes cleared focus. The new
// row has no Viva identity yet; it must not match the cleared focus.
f.setRows("first", "original", "new")
if !f.view.RowID(2).IsZero() {
t.Fatal("the new row already has an identity")
}
canvas := new(gfx.Canvas)
f.sync(canvas)
f.wantSelection(t, "original", 1)
if !f.focus.IsZero() {
t.Fatal("cleared focus was not recorded")
}

// With focus unchanged at zero, a toolbar reveal must also preserve the
// selection and must not give the keyboard to an unpainted row.
*f.reveal = true
f.sync(canvas)
f.wantSelection(t, "original", 1)
if *f.reveal || !canvas.FocusRequest().IsZero() {
t.Fatal("reveal did not finish without taking focus")
}

// Returning to the same identity used before focus cleared is a new
// focus change and must select it, even though another row was kept.
canvas.SetInteraction(gfx.ID{}, gfx.ID{}, f.view.RowID(0), true)
f.sync(canvas)
f.wantSelection(t, "first", 0)
})
}
}

func TestResultTreesSelectionFollowsArrowKeys(t *testing.T) {
for _, panel := range []string{"references", "problems"} {
t.Run(panel, func(t *testing.T) {
f := newResultTreeFocus(t, panel)
// Tab enters the currently selected row; arrows then use Viva's own
// navigation and the panel observes the focused row on the next frame.
for _, key := range []gfx.Key{gfx.KeyTab, gfx.KeyUp} {
if err := f.driver.Key(key, 0); err != nil {
t.Fatal(err)
}
f.paint(t)
}
f.wantSelection(t, "first", 0)
if err := f.driver.Key(gfx.KeyDown, 0); err != nil {
t.Fatal(err)
}
f.paint(t)
f.wantSelection(t, "original", 1)
})
}
}

func TestResultTreesRevealKeepsTheSelectionMadeOutsideTheTree(t *testing.T) {
for _, panel := range []string{"references", "problems"} {
t.Run(panel, func(t *testing.T) {
f := newResultTreeFocus(t, panel)
canvas := new(gfx.Canvas)
canvas.SetInteraction(gfx.ID{}, gfx.ID{}, f.view.RowID(0), true)
f.sync(canvas)
f.wantSelection(t, "first", 0)

// A toolbar action changed the selection while the first row still has
// focus. Revealing it transfers focus without reverting the selection.
*f.selected, *f.selectedRow, *f.reveal = "original", 1, true
f.sync(canvas)
f.wantSelection(t, "original", 1)
if *f.reveal || canvas.FocusRequest() != f.view.RowID(1) {
t.Fatal("reveal did not hand focus to the selected row")
}

// An unrelated control's focus cannot change the selection, including
// after the result becomes empty while a stale focus identity remains.
canvas = new(gfx.Canvas)
canvas.SetInteraction(gfx.ID{}, gfx.ID{}, gfx.Item(99), true)
*f.reveal = true
f.sync(canvas)
f.wantSelection(t, "original", 1)
if !canvas.FocusRequest().IsZero() {
t.Fatal("reveal took focus from another control")
}
f.setRows()
f.sync(canvas)
if f.view.Selected() != -1 {
t.Fatal("the empty tree still selects a row")
}
})
}
}
Loading
Loading