From a739ad9b5d123d25936328f32b17b670c3354b8a Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 15:21:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20=E5=90=8C=E6=AD=A5=20Viva=20?= =?UTF-8?q?=E4=B8=8A=E6=B8=B8=E5=B9=B6=E5=8D=87=E7=BA=A7=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E6=A0=91=E8=A1=8C=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=95=B4=E8=A1=8C=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - go.mod 固定到 Lithe-IDEA/Lithe-viva main 27ad1d7(含上游 1fc84f6 的 merge commit 同步 #21 和 #20),require 升到上游 1fc84f6。 - 项目树、调试变量、Git 日志引用、插件原生树四处行菜单改用上游 Box.LabelFor + ui.ContextMenu:名字为整行作标签,右键行内任意位置都打开菜单;删除各自的指针转发、菜单状态字段和 named 分支。 - 编辑器操作栏菜单改用上游 ui.ContextMenuAt,删除 MenuAt 补丁依赖。 - 恢复 Viva#9 跳过的 TestProjectTreeOpenSelectedFollowsTheKeymap;新增 TestProjectTreeRowMenuOpensPastTheName 和行菜单无头截图 TestVisualRowMenuPastTheName。 - 项目树横向滚轮转发保留:上游 Tree 仍未注册横向滚轮路由(#1821 第 3 项)。 --- desktop/go.mod | 4 +- desktop/go.sum | 6 +- desktop/internal/workbench/debug_menus.go | 37 +-------- .../internal/workbench/debug_sections_view.go | 9 +-- desktop/internal/workbench/debug_variables.go | 2 - desktop/internal/workbench/editor_view.go | 2 +- desktop/internal/workbench/filetree.go | 5 +- .../workbench/filetree_actions_test.go | 4 - desktop/internal/workbench/filetree_menu.go | 16 ++-- .../internal/workbench/filetree_menu_test.go | 24 ++++++ desktop/internal/workbench/filetree_view.go | 34 +++------ desktop/internal/workbench/gitlog_page.go | 8 +- desktop/internal/workbench/gitlog_ref_menu.go | 37 ++------- .../workbench/gitlog_ref_menu_test.go | 4 +- desktop/internal/workbench/gitlog_view.go | 14 ++-- desktop/internal/workbench/plugin_native.go | 44 ++--------- .../internal/workbench/visual_capture_test.go | 76 +++++++++++++++++++ 17 files changed, 160 insertions(+), 166 deletions(-) diff --git a/desktop/go.mod b/desktop/go.mod index 2442224d44..e4ec9c93e8 100644 --- a/desktop/go.mod +++ b/desktop/go.mod @@ -9,7 +9,7 @@ toolchain go1.27.3 require ( github.com/creack/pty v1.1.24 github.com/tailscale/hujson v0.0.0-20260727124030-b80ff77dac4f - github.com/vivaui/viva v0.6.4-0.20261114064951-b63e4a0994d3 + github.com/vivaui/viva v0.6.5-0.20261115063318-1fc84f6ff1d3 github.com/zalando/go-keyring v0.2.8 golang.org/x/sys v0.50.0 ) @@ -20,4 +20,4 @@ require ( github.com/godbus/dbus/v5 v5.2.2 // indirect ) -replace github.com/vivaui/viva => github.com/Lithe-IDEA/viva v0.6.3-0.20261114132607-4829f2bdde18 +replace github.com/vivaui/viva => github.com/Lithe-IDEA/viva v0.6.5-0.20261115071107-27ad1d78b978 diff --git a/desktop/go.sum b/desktop/go.sum index b23284647a..6c18f2db2d 100644 --- a/desktop/go.sum +++ b/desktop/go.sum @@ -1,5 +1,5 @@ -github.com/Lithe-IDEA/viva v0.6.3-0.20261114132607-4829f2bdde18 h1:2SRDSXAk+1fHMJ6B8lTlcPrPoz0zGm0rJXXowlOgDFE= -github.com/Lithe-IDEA/viva v0.6.3-0.20261114132607-4829f2bdde18/go.mod h1:e9In6+J77G7B9ow4enZ2FSOFh7U3q4cQ5iJr3Qn/Olk= +github.com/Lithe-IDEA/viva v0.6.5-0.20261115071107-27ad1d78b978 h1:h7klV5KTgiPRDE0zFUFk6ky32ZUBcf9yEATOXKYcg1o= +github.com/Lithe-IDEA/viva v0.6.5-0.20261115071107-27ad1d78b978/go.mod h1:e9In6+J77G7B9ow4enZ2FSOFh7U3q4cQ5iJr3Qn/Olk= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= @@ -14,6 +14,8 @@ github.com/gabstv/go-bsdiff v1.0.5 h1:g29MC/38Eaig+iAobW10/CiFvPtin8U3Jj4yNLcNG9 github.com/gabstv/go-bsdiff v1.0.5/go.mod h1:/Zz6GK+/f/TMylRtVaW3uwZlb0FZITILfA0q12XKGwg= github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY= github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/desktop/internal/workbench/debug_menus.go b/desktop/internal/workbench/debug_menus.go index 19a7603fbb..cc4ee3c89e 100644 --- a/desktop/internal/workbench/debug_menus.go +++ b/desktop/internal/workbench/debug_menus.go @@ -8,7 +8,6 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/app" - "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -22,15 +21,6 @@ import ( // others. Each item acts // through the action the panel's own controls run. -// debugVarMenu is the open context menu of one row of the variables tree. A tree row is -// painted by the tree, so its menu is opened from the right-click on the row and declared -// after the tree. -type debugVarMenu struct { - open bool - at ui.Rect - node *debugVarNode -} - // copyDebugText puts one value the debugger shows on the clipboard. func (a *App) copyDebugText(action, text string) { a.performed(action, surfaceContextMenu) @@ -150,32 +140,13 @@ func (a *App) debugInstructionMenu(c ui.C, row ui.Box, p *project, instruction c }) } -// debugVariablePointer opens the menu of variable row i when the row is right-clicked. -func (a *App) debugVariablePointer(c ui.C, p *project, i int, node *debugVarNode) { - v := &p.debug.vars - canvas := c.Canvas() - if node.moreFor != nil || canvas == nil { - return - } - event, ok := canvas.PointerOn(v.tree.RowID(i)) - if !ok || event.Kind != gfx.PointerDown || event.Button != gfx.PointerButtonSecondary { - return - } - canvas.Consume() - v.menu = debugVarMenu{open: true, at: ui.Rect{X: event.X, Y: event.Y}, node: node} -} - -// debugVariableMenu declares the menu of the variable right-clicked while it is open: Set -// Value selects the row, which shows the field that gives it a new value; Break on Field +// debugVariableMenu is the menu of one variable, opened from its name or anywhere on its row: +// Set Value selects the row, which shows the field that gives it a new value; Break on Field // Access watches it; Add to Watches evaluates its expression at each stop. -func (a *App) debugVariableMenu(c ui.C, p *project) { +func (a *App) debugVariableMenu(c ui.C, name ui.Box, p *project, node *debugVarNode) { d := &p.debug v := &d.vars - if !v.menu.open { - return - } - node := v.menu.node - ui.MenuAt(c.Key("debug-var-menu"), v.menu.at.X, v.menu.at.Y, &v.menu.open, func(menu *ui.MenuItems) { + ui.ContextMenu(c, name, func(menu *ui.MenuItems) { lang := a.language() menu.WidthRange(180, 260) edits := canEditDebugVariable(d, node) diff --git a/desktop/internal/workbench/debug_sections_view.go b/desktop/internal/workbench/debug_sections_view.go index e8c754b973..0b4f8a02ec 100644 --- a/desktop/internal/workbench/debug_sections_view.go +++ b/desktop/internal/workbench/debug_sections_view.go @@ -158,14 +158,12 @@ func (a *App) debugVariablesTree(c ui.C, p *project) { rows := v.flatten() ui.Tree(c, &v.tree, len(rows), v.label, func(i int) { node := rows[i] - a.debugVariablePointer(c, p, i, node) if node.moreFor != nil { a.debugVariableStatusRow(c, node, t.LoadingVariables, t.LoadMore) return } - a.debugVariableRow(c, node) + a.debugVariableRow(c, p, v.tree.RowID(i), node) }).Scrollbars().Grow(1).FillWidth() - a.debugVariableMenu(c, p) if i, ok := v.tree.Toggled(); ok && i < len(rows) { node := rows[i] c.After(func() { @@ -184,7 +182,7 @@ func (a *App) debugVariablesTree(c ui.C, p *project) { // debugVariableRow declares one variable as IntelliJ IDEA writes it, "name = {type} value", after // an icon that tells a value with children from a plain one. A scope is its name alone. -func (a *App) debugVariableRow(c ui.C, node *debugVarNode) { +func (a *App) debugVariableRow(c ui.C, p *project, row gfx.ID, node *debugVarNode) { icon := icons.Variable switch { case node.scope: @@ -193,7 +191,8 @@ func (a *App) debugVariableRow(c ui.C, node *debugVarNode) { icon = icons.Braces } ui.Icon(c, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) - ui.Text(c, node.name).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium) + name := ui.Text(c, node.name).Shrink(0).FontSize(12.5).Color(treelist.Text(a.colors.Dark)).Weight(gfx.WeightMedium).LabelFor(row) + a.debugVariableMenu(c, name, p, node) if node.scope || (node.value == "" && node.typeName == "") { return } diff --git a/desktop/internal/workbench/debug_variables.go b/desktop/internal/workbench/debug_variables.go index 2d57132705..fe8253def7 100644 --- a/desktop/internal/workbench/debug_variables.go +++ b/desktop/internal/workbench/debug_variables.go @@ -82,8 +82,6 @@ type debugVariables struct { // selected is the variable row the edit field acts on. selected *debugVarNode edit debugVariableEdit - // menu is the context menu of the row right-clicked. - menu debugVarMenu // json shows the loaded tree as JSON instead. json bool // registersView shows the registers scope alone, as the Registers tab does; the Variables tab lists diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index 2cd3060624..e16c738215 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -182,7 +182,7 @@ func (a *App) documentView(c ui.C, group string, d *document) { if p := a.project; p != nil && !d.virtual { ui.ContextMenu(c.Key("menu"+name), box, a.editorMenuItems(c, p, d)) at := d.actionPanel.menuAt - ui.MenuAt(c.Key("lanemenu"+name), at.X, at.Y+at.Height, &d.actionPanel.menuOpen, a.editorActionLaneMenu(c, p, d)) + ui.ContextMenuAt(c.Key("lanemenu"+name), box, &d.actionPanel.menuOpen, gfx.Point{X: at.X, Y: at.Y + at.Height}, a.editorActionLaneMenu(c, p, d)) a.gitGutterPeek(c, p, d, box) } } diff --git a/desktop/internal/workbench/filetree.go b/desktop/internal/workbench/filetree.go index 75e8d1e24e..ab1336bb22 100644 --- a/desktop/internal/workbench/filetree.go +++ b/desktop/internal/workbench/filetree.go @@ -48,8 +48,9 @@ type fileTree struct { // removal is the Delete dialog, open while the user chooses between the trash and deleting // for good (filetree_batch.go). removal treeRemoval - // rowRefs maps the hit identity of each row the last paint declared to its node, so a drag - // or drop finds the paths it names (filetree_dnd.go); clip is the cut or copied items. + // rowRefs maps the identity of each row the last paint declared (view.RowID, which the row's + // name labels) to its node, so a drag or drop finds the paths it names (filetree_dnd.go); + // clip is the cut or copied items. rowRefs map[gfx.ID]treeRowRef clip treeClipboard // failed is why the root could not be listed; empty otherwise. diff --git a/desktop/internal/workbench/filetree_actions_test.go b/desktop/internal/workbench/filetree_actions_test.go index 7a44e9e1c7..9ca84451a4 100644 --- a/desktop/internal/workbench/filetree_actions_test.go +++ b/desktop/internal/workbench/filetree_actions_test.go @@ -346,10 +346,6 @@ func (h *harness) treeRowOwned(id gfx.ID) bool { // A click on a file would open it at once, so a click on an empty folder gives the tree the // keyboard and the arrows pick the file. func TestProjectTreeOpenSelectedFollowsTheKeymap(t *testing.T) { - // The pinned Viva leaves a Tree's focused rows outside the box Tree returns, so no - // Shortcut on the project tree acts while a row has the focus. Remove this skip with the - // pin that carries Lithe-IDEA/viva#9 (vivaui/viva#234). - t.Skip("needs Box.Shortcut to cover Tree rows: Lithe-IDEA/viva#9") root := t.TempDir() if err := os.Mkdir(filepath.Join(root, "empty"), 0o700); err != nil { t.Fatal(err) diff --git a/desktop/internal/workbench/filetree_menu.go b/desktop/internal/workbench/filetree_menu.go index ddb9864bc8..d1413f88ba 100644 --- a/desktop/internal/workbench/filetree_menu.go +++ b/desktop/internal/workbench/filetree_menu.go @@ -11,6 +11,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/wslpath" "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -49,16 +50,17 @@ type treePrompt struct { err string } -// projectTreeMenu declares the context menu of one row. A row of a folder or the root can make -// files and folders; any row but the root can be renamed or deleted. The Git items appear only -// for a file the last status lists as changed. -func (a *App) projectTreeMenu(c ui.C, p *project, n *treeNode, target ui.Box) { +// projectTreeMenu makes the name of row the label of that row and declares the row's context +// menu on it, so the menu opens from anywhere on the row, and any row but the root is dragged +// from anywhere on it too. A row of a folder or the root can make files and folders; any row +// but the root can be renamed or deleted. The Git items appear only for a file the last status +// lists as changed. +func (a *App) projectTreeMenu(c ui.C, p *project, row gfx.ID, n *treeNode, target ui.Box) { language := a.language() root := n == p.tree.root - rowID := ui.ID(c.Key("treectx/" + n.path)) - target.Hit(rowID, n.name) + target.LabelFor(row) if !root { - p.tree.rememberRow(rowID, n) + p.tree.rememberRow(row, n) target.DragSource(&a.dnd.tree) } if n.dir && !root { diff --git a/desktop/internal/workbench/filetree_menu_test.go b/desktop/internal/workbench/filetree_menu_test.go index 9ac50de433..ed131c918b 100644 --- a/desktop/internal/workbench/filetree_menu_test.go +++ b/desktop/internal/workbench/filetree_menu_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/vivaui/viva/gfx" ) // stubTreeTrash replaces the system trash for one test and returns the paths moved to it, so a @@ -75,6 +76,29 @@ func TestProjectTreeCopyPathSubmenu(t *testing.T) { } } +// The name of a tree row labels its row: it is no stop of its own for Tab, and the row's menu +// opens from the empty part of the row past the name, acting on that row. +func TestProjectTreeRowMenuOpensPastTheName(t *testing.T) { + root := t.TempDir() + writeTreeFiles(t, root, "a.txt", "b.txt") + h := newHarness(t, &testKernel{Client: core.NewClient()}) + p := h.openTree(t, root) + + row, name := h.treeRowHit("b.txt"), h.treeNameHit("b.txt") + if !name.IsLabel || name.ID != row.ID || name.Focusable { + t.Fatalf("the name hit is %+v, want a label of row %v that takes no focus", name, row.ID) + } + if err := h.driver.ClickButton(row.Bounds.X+row.Bounds.Width-20, row.Bounds.Y+row.Bounds.Height/2, gfx.PointerButtonSecondary); err != nil { + t.Fatal(err) + } + h.settle() + h.click(center(h.popupHit(h.shared("desktop.files.delete")))) + h.settle() + if !p.tree.removal.open || !slices.Equal(p.tree.removal.paths, []string{"b.txt"}) { + t.Fatalf("Delete from the right-click past the name opened %+v, want the dialog for b.txt", p.tree.removal) + } +} + // treePromptFor opens one row's dialog in the test without a click: the dialog itself is // declared by the next frame, and the action is what the test drives. func treePromptFor(h *harness, p *project, kind treePromptKind, n *treeNode, name string) { diff --git a/desktop/internal/workbench/filetree_view.go b/desktop/internal/workbench/filetree_view.go index 261d60620f..11e00b1951 100644 --- a/desktop/internal/workbench/filetree_view.go +++ b/desktop/internal/workbench/filetree_view.go @@ -76,7 +76,6 @@ func (a *App) projectTree(c ui.C, p *project) { t.view.RowWidth = a.measureTree(c.Canvas(), t) // Names are never cut short: the rows are as wide as the widest one, and the tree // scrolls sideways to show the rest of it. - named := -1 // IDEA's own disclosure arrows: filled 16 point geometry in the row's existing slot, // so only the arrow changes and no row moves. t.view.Disclosure = &components.TreeDisclosure{ @@ -85,9 +84,7 @@ func (a *App) projectTree(c ui.C, p *project) { Size: 16, } tree := ui.Tree(c, &t.view, len(t.rows), t.label, func(i int) { - if a.drawTreeContent(c, p, t.rows[i]) { - named = i - } + a.drawTreeContent(c, p, t.view.RowID(i), t.rows[i]) }).Scrollbars().Grow(1).FillWidth().PadY(treelist.PadY) if a.elementShortcut(tree, shortcuts.OpenSelected) { c.After(func() { a.openSelectedTreeFile(p) }) @@ -106,15 +103,7 @@ func (a *App) projectTree(c ui.C, p *project) { // first one left it. Enter is a choice with no click behind it. info, clicked := c.Canvas().ClickInfo() repeated := clicked && info.Clicks >= 2 - i, ok := t.view.Chosen() - if !ok && named >= 0 { - // The name is the target of the row's context menu, which takes the click before the - // Tree sees it, so a click on the name is a click on its row. Viva's Tree gives a row - // no other place for a context menu; once the pinned Viva has Box.LabelFor - // (vivaui/viva#221), the name labels its row and this goes (#1821). - i, ok = named, true - } - if ok && i < len(t.rows) { + if i, ok := t.view.Chosen(); ok && i < len(t.rows) { n := t.rows[i] // The row a click chose takes the keyboard, so the arrow keys go on from it. c.Canvas().RequestFocus(t.view.RowID(i)) @@ -193,13 +182,12 @@ func (a *App) measureTree(canvas *gfx.Canvas, t *fileTree) float32 { return width + treeScrollPad } -// drawTreeContent declares what a row of the tree shows after its chevron: the node's icon and -// its name, the root's in bold, and reports whether this paint delivers a click on the name. -// Viva's Tree starts a row without a chevron (a file, an empty folder) where the chevron of a -// folder at its depth is, so such a row keeps the chevron's room empty, and its icon lines up -// with the icons of the folders beside it. -func (a *App) drawTreeContent(c ui.C, p *project, n *treeNode) bool { - clicked := false +// drawTreeContent declares what row of the tree shows after its chevron: the node's icon and its +// name, the root's in bold, which labels the row and carries its context menu. Viva's Tree +// starts a row without a chevron (a file, an empty folder) where the chevron of a folder at its +// depth is, so such a row keeps the chevron's room empty, and its icon lines up with the icons +// of the folders beside it. +func (a *App) drawTreeContent(c ui.C, p *project, row gfx.ID, n *treeNode) { content := func() { icon := fileicons.ForFile(n.name, a.colors.Dark) if n.dir { @@ -210,15 +198,13 @@ func (a *App) drawTreeContent(c ui.C, p *project, n *treeNode) bool { if n == p.tree.root { name.Bold() } - a.projectTreeMenu(c, p, n, name) - clicked = name.Clicked() + a.projectTreeMenu(c, p, row, n, name) } if n.dir && !n.empty { content() - return clicked + return } ui.Row(c).Shrink(0).Items(ui.Center).Gap(c.Theme().Metrics.GapItem).PadLeft(treeChevron).Children(content) - return clicked } // focusTreeRow gives the keyboard to the row the locate button brought into view, once the row diff --git a/desktop/internal/workbench/gitlog_page.go b/desktop/internal/workbench/gitlog_page.go index f2201c06f1..4b0eea653c 100644 --- a/desktop/internal/workbench/gitlog_page.go +++ b/desktop/internal/workbench/gitlog_page.go @@ -113,12 +113,6 @@ type logView struct { // refLabel names the rows of refs, made once because a method value made in each paint // allocates. refLabel func(int) string - // refMenu says the menu of a reference is open, at refMenuAt, on refMenuRef of the repository - // refMenuRoot (gitlog_ref_menu.go). - refMenu bool - refMenuAt ui.Rect - refMenuRef core.GitReference - refMenuRoot string // compareSource is the reference Select for Compare picked in the repository compareRoot, // which the menu of another reference then compares with. compareSource *core.GitReference @@ -190,7 +184,7 @@ func (v *logView) reset() { v.keyRows, v.keys = nil, nil v.files = ui.ListState{} v.refs.ListState = ui.ListState{} - v.refMenu, v.compareSource, v.compareRoot = false, nil, "" + v.compareSource, v.compareRoot = nil, "" } // capture keeps the width the commit list and the details shared, and takes a drag of the diff --git a/desktop/internal/workbench/gitlog_ref_menu.go b/desktop/internal/workbench/gitlog_ref_menu.go index c104c3ddde..0fb4fae88f 100644 --- a/desktop/internal/workbench/gitlog_ref_menu.go +++ b/desktop/internal/workbench/gitlog_ref_menu.go @@ -6,7 +6,6 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/app" - "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -49,37 +48,11 @@ type historyIntegrateState struct { root string } -// logRefPointer opens the reference menu of row i of the reference pane when it is pressed with -// the secondary button. A Tree has no menu of its own rows, so the press is read on the row. -func (a *App) logRefPointer(c ui.C, p *project, i int) { - v := &a.logView - row := v.refItems[i] - canvas := c.Canvas() - if row.kind != logRefReference || row.ref == nil || canvas == nil { - return - } - event, ok := canvas.PointerOn(v.refs.RowID(i)) - if !ok || event.Kind != gfx.PointerDown || event.Button != gfx.PointerButtonSecondary { - return - } - canvas.Consume() - v.refMenu, v.refMenuAt, v.refMenuRef = true, ui.Rect{X: event.X, Y: event.Y}, *row.ref - v.refMenuRoot = p.logRepositoryRoot() -} - -// drawLogRefMenu declares the reference menu while it is open. -func (a *App) drawLogRefMenu(c ui.C, p *project) { - v := &a.logView - if !v.refMenu { - return - } - if v.refMenuRoot != p.logRepositoryRoot() { - // The log walks another repository now; the reference is not one of it. - v.refMenu = false - return - } - ui.MenuAt(c.Key("log-ref-menu"), v.refMenuAt.X, v.refMenuAt.Y, &v.refMenu, func(menu *ui.MenuItems) { - a.drawLogRefMenuItems(c, menu, p, v.refMenuRef) +// drawLogRefMenu gives the name of a reference row the menu of reference r, which opens from +// the name or anywhere on its row, with Shift+F10 too while the row has the focus. +func (a *App) drawLogRefMenu(c ui.C, name ui.Box, p *project, r core.GitReference) { + ui.ContextMenu(c, name, func(menu *ui.MenuItems) { + a.drawLogRefMenuItems(c, menu, p, r) }) } diff --git a/desktop/internal/workbench/gitlog_ref_menu_test.go b/desktop/internal/workbench/gitlog_ref_menu_test.go index 7adc68839d..0b54fcc526 100644 --- a/desktop/internal/workbench/gitlog_ref_menu_test.go +++ b/desktop/internal/workbench/gitlog_ref_menu_test.go @@ -40,8 +40,8 @@ func (h *harness) logRefMenu(short string) { h.t.Fatal(err) } h.settle() - if !v.refMenu || v.refMenuRef.ShortName != short { - h.t.Fatalf("the reference menu is open %v on %q, want it open on %q", v.refMenu, v.refMenuRef.ShortName, short) + if item := h.app.text.Branch.NewBranchFrom(short); !h.hasPopupItem(item) { + h.t.Fatalf("no menu item %q is shown after the right-click on %q", item, short) } } diff --git a/desktop/internal/workbench/gitlog_view.go b/desktop/internal/workbench/gitlog_view.go index d099dd65a1..c0806c1bd8 100644 --- a/desktop/internal/workbench/gitlog_view.go +++ b/desktop/internal/workbench/gitlog_view.go @@ -181,10 +181,8 @@ func (a *App) drawLogReferences(c ui.C, p *project) ui.Box { }) ui.Divider(c) ui.Tree(c, &v.refs, len(v.refItems), v.refLabel, func(i int) { - a.logRefPointer(c, p, i) - a.drawLogRefContent(c, v.refItems[i]) + a.drawLogRefContent(c, p, v.refs.RowID(i), v.refItems[i]) }).Scrollbars().Grow(1).PadY(4) - a.drawLogRefMenu(c, p) if i, ok := v.refs.Toggled(); ok { c.After(func() { a.toggleLogRef(p, v.refItems[i], query) }) } @@ -279,8 +277,9 @@ func (v *logView) refNode(i int) ui.TreeNode { // refRowLabel is the accessible name of row i of the reference pane. func (v *logView) refRowLabel(i int) string { return v.refItems[i].label } -// drawLogRefContent declares what a row of the reference pane shows after its arrow. -func (a *App) drawLogRefContent(c ui.C, r logRefRow) { +// drawLogRefContent declares what row of the reference pane shows after its arrow. The name of +// a reference of the repository the log walks labels the row and carries the reference's menu. +func (a *App) drawLogRefContent(c ui.C, p *project, row gfx.ID, r logRefRow) { switch r.kind { case logRefSection: ui.Text(c, r.label).Weight(gfx.WeightMedium).Ellipsis().Grow(1) @@ -311,7 +310,10 @@ func (a *App) drawLogRefContent(c ui.C, r logRefRow) { trailing = strings.TrimSpace(trailing + " ↓" + strconv.Itoa(ref.Behind)) } ui.Icon(c, icon).Size(14, 14).Color(referenceColor(kind, a.colors.Dark)) - ui.Text(c, r.label).Ellipsis().Grow(1) + name := ui.Text(c, r.label).Ellipsis().Grow(1) + if r.kind == logRefReference { + a.drawLogRefMenu(c, name.LabelFor(row), p, *ref) + } if trailing != "" { ui.Text(c, trailing).Muted().FontSize(a.theme.Metrics.FontSizeS).Shrink(0) } diff --git a/desktop/internal/workbench/plugin_native.go b/desktop/internal/workbench/plugin_native.go index 6a43b648d4..b5276b17db 100644 --- a/desktop/internal/workbench/plugin_native.go +++ b/desktop/internal/workbench/plugin_native.go @@ -34,9 +34,6 @@ type nativePanelState struct { rows []nativeRow busy bool message string - // menu is the context menu of the tree row right-clicked. A tree row is painted by the tree, - // so its menu is opened from the right-click on the row and declared after the tree. - menu nativeRowMenu // revealed says the toolbar shows: the pointer is over the panel, or the keyboard or assistive focus is on // one of its buttons. It is read from the previous paint, so the toolbar keeps its place either way. revealed bool @@ -280,15 +277,8 @@ func (a *App) nativeMessage(c ui.C, state *nativePanelState) { func (a *App) nativeTree(c ui.C, p *project, tool *pluginservice.ToolWindow, state *nativePanelState) { rows := state.rows ui.Tree(c, &state.tree, len(rows), func(i int) string { return rows[i].node.Label }, func(i int) { - a.nativeRowPointer(c, tool, state, i, rows[i].node.ID) - a.nativeRowContent(c.KeyInt(i), rows[i]) + a.nativeRowContent(c.KeyInt(i), p, tool, state, state.tree.RowID(i), rows[i]) }).Scrollbars().Label(tool.Title).Grow(1).FillWidth() - if state.menu.open { - id := state.menu.id - ui.MenuAt(c.Key("native-row-menu"), state.menu.at.X, state.menu.at.Y, &state.menu.open, func(menu *ui.MenuItems) { - a.nativeMenuItems(c, menu, p, tool, state, id) - }) - } toggled, didToggle := state.tree.Toggled() if didToggle && toggled < len(rows) { id := rows[toggled].node.ID @@ -306,32 +296,12 @@ func (a *App) nativeTree(c ui.C, p *project, tool *pluginservice.ToolWindow, sta } } -// nativeRowMenu is the open context menu of one tree row: where it opened and the node it acts on. -type nativeRowMenu struct { - open bool - at ui.Rect - id string -} - -// nativeRowPointer opens the panel's context menu on tree row i, the node id, when the row is -// right-clicked and the panel declares one. -func (a *App) nativeRowPointer(c ui.C, tool *pluginservice.ToolWindow, state *nativePanelState, i int, id string) { - canvas := c.Canvas() - if len(tool.Native.ContextMenu) == 0 || canvas == nil { - return - } - event, ok := canvas.PointerOn(state.tree.RowID(i)) - if !ok || event.Kind != gfx.PointerDown || event.Button != gfx.PointerButtonSecondary { - return - } - canvas.Consume() - state.menu = nativeRowMenu{open: true, at: ui.Rect{X: event.X, Y: event.Y}, id: id} -} - -// nativeRowContent declares what a tree row shows after its chevron. -func (a *App) nativeRowContent(c ui.C, row nativeRow) { +// nativeRowContent declares what tree row shows after its chevron. The label names the row, so +// the panel's context menu it carries opens from anywhere on the row. +func (a *App) nativeRowContent(c ui.C, p *project, tool *pluginservice.ToolWindow, state *nativePanelState, row gfx.ID, item nativeRow) { ui.Row(c).Grow(1).Shrink(1).Items(ui.Center).Gap(6).Children(func() { - ui.Text(c, row.node.Label).Grow(1).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis() + label := ui.Text(c, item.node.Label).Grow(1).Shrink(1).FontSize(12.5).Color(a.colors.Text).Ellipsis().LabelFor(row) + a.nativeContextMenu(c, label, p, tool, state, item.node.ID) }) } @@ -354,7 +324,7 @@ func (a *App) nativeList(c ui.C, p *project, tool *pluginservice.ToolWindow, sta }).Scrollbars().Label(tool.Title).Grow(1).FillWidth() } -// nativeContextMenu attaches the panel's context menu to a list row. +// nativeContextMenu attaches the panel's context menu to a list row or to the label of a tree row. func (a *App) nativeContextMenu(c ui.C, target ui.Box, p *project, tool *pluginservice.ToolWindow, state *nativePanelState, id string) { if len(tool.Native.ContextMenu) == 0 { return diff --git a/desktop/internal/workbench/visual_capture_test.go b/desktop/internal/workbench/visual_capture_test.go index 2656de12a6..f22a62aa5d 100644 --- a/desktop/internal/workbench/visual_capture_test.go +++ b/desktop/internal/workbench/visual_capture_test.go @@ -6,6 +6,7 @@ import ( "io/fs" "os" "path/filepath" + "slices" "strings" "testing" "time" @@ -15,6 +16,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/localshell" "github.com/1lck/Lithe-IDEA/desktop/internal/store" "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/headless" ) @@ -418,3 +420,77 @@ func TestVisualDebugAnnouncedAdapterExitedFirst(t *testing.T) { } } } + +// TestVisualRowMenuPastTheName captures the context menu of a project tree row and of a Git +// reference row, each opened by a right-click on the empty part of the row past its name: the +// name labels its row, so the whole row carries the menu. It needs only LITHE_VISUAL_OUTPUT_DIR. +func TestVisualRowMenuPastTheName(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + // rightClickPastTheName right-clicks row near its right end, well past the name it starts + // with. + rightClickPastTheName := func(h *harness, row gfx.Rect) { + t.Helper() + if err := h.driver.ClickButton(row.X+row.Width-24, row.Y+row.Height/2, gfx.PointerButtonSecondary); err != nil { + t.Fatal(err) + } + h.settle() + } + for _, theme := range []string{"dark", "light"} { + for _, language := range []string{"zh-Hans", "en-US"} { + open := func(t *testing.T, kernel Kernel) (*harness, *headless.Session) { + var session *headless.Session + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, map[string]string{"theme": theme}); err != nil { + t.Fatal(err) + } + h := newHarnessWithDriver(t, Options{Kernel: kernel, Store: prefs, Languages: []string{language}}, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1000, 640 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + return h, session + } + t.Run("tree-"+theme+"-"+language, func(t *testing.T) { + root := t.TempDir() + writeTreeFiles(t, root, "src/main.txt", "notes.txt", "readme.txt") + h, session := open(t, &testKernel{Client: core.NewClient()}) + h.openTree(t, root) + rightClickPastTheName(h, h.treeRowHit("notes.txt").Bounds) + if !h.hasPopupItem(h.shared("desktop.files.delete")) { + t.Fatal("the right-click past the name of notes.txt opened no menu") + } + if err := session.Screenshot(filepath.Join(out, "tree-row-menu-past-name-"+theme+"-"+language+".png")); err != nil { + t.Fatal(err) + } + }) + t.Run("gitlog-"+theme+"-"+language, func(t *testing.T) { + dir := newTestRepository(t) + gitRun(t, dir, "branch", "topic") + h, session := open(t, gitKernel{core.NewClient()}) + h.openLog(t, dir) + v := &h.app.logView + i := slices.IndexFunc(v.refItems, func(r logRefRow) bool { return r.kind == logRefReference && r.short == "topic" }) + if i < 0 { + t.Fatal("the reference pane shows no row of topic") + } + rightClickPastTheName(h, h.topHit(v.refs.RowID(i))) + if item := h.app.text.Branch.NewBranchFrom("topic"); !h.hasPopupItem(item) { + t.Fatal("the right-click past the name of topic opened no menu") + } + if err := session.Screenshot(filepath.Join(out, "gitlog-ref-menu-past-name-"+theme+"-"+language+".png")); err != nil { + t.Fatal(err) + } + }) + } + } +}