Archived
Update a pin that is behind with u; switch fast-forwards
`u` moves the pin of the selection to the tip of its ref when the pin is only behind it: a switch to that branch with exactly the tip the row shows, nothing fetched; if the ref moved meanwhile, nothing happens. On the superproject it fast-forwards the branch to its upstream and restores the submodules (git pull --ff-only from the last fetch). Switch now fast-forwards a local branch that is only behind the chosen remote branch, unless another worktree has it checked out, and keeps a checked-out branch that tracks it under another name. A branch with commits of its own is still never moved. Stage pin is dropped: switching to the branch already stages it. The detail pane's palette wraps instead of cutting off keys. Add D29 and F59. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -55,20 +55,41 @@ func (m Model) View(s *submodule.Submodule, repo *submodule.Repo) string {
|
||||
lines[i] = ansi.Truncate(l, m.width, "…")
|
||||
}
|
||||
height := m.height
|
||||
var palette string
|
||||
var palette []string
|
||||
if m.PaletteVisible() {
|
||||
height-- // the palette is the last line
|
||||
m.help.Width = 0
|
||||
palette = ansi.Truncate(m.help.ShortHelpView(m.actions), m.width, "…")
|
||||
palette = m.palette()
|
||||
height -= len(palette) // the palette is at the bottom
|
||||
}
|
||||
if len(lines) > height {
|
||||
lines = lines[:height]
|
||||
}
|
||||
body := lipgloss.NewStyle().Width(m.width).Height(height).Render(strings.Join(lines, "\n"))
|
||||
if palette == "" {
|
||||
if len(palette) == 0 {
|
||||
return body
|
||||
}
|
||||
return body + "\n" + palette
|
||||
return body + "\n" + strings.Join(palette, "\n")
|
||||
}
|
||||
|
||||
// palette lays the actions out on as many lines as the width needs, so no
|
||||
// key is cut off.
|
||||
func (m Model) palette() []string {
|
||||
m.help.Width = 0
|
||||
var out []string
|
||||
var cur []key.Binding
|
||||
for _, b := range m.actions {
|
||||
if len(cur) > 0 && lipgloss.Width(m.help.ShortHelpView(append(cur, b))) > m.width {
|
||||
out = append(out, m.help.ShortHelpView(cur))
|
||||
cur = nil
|
||||
}
|
||||
cur = append(cur, b)
|
||||
}
|
||||
if len(cur) > 0 {
|
||||
out = append(out, m.help.ShortHelpView(cur))
|
||||
}
|
||||
for i, l := range out {
|
||||
out[i] = ansi.Truncate(l, m.width, "…")
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (m Model) lines(s *submodule.Submodule, repo *submodule.Repo) []string {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package detail
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"submarine/internal/tui/theme"
|
||||
)
|
||||
|
||||
func TestPaletteWrapsInsteadOfCuttingKeys(t *testing.T) {
|
||||
keys := []key.Binding{
|
||||
key.NewBinding(key.WithKeys("c"), key.WithHelp("c", "copy path")),
|
||||
key.NewBinding(key.WithKeys("u"), key.WithHelp("u", "update pin")),
|
||||
key.NewBinding(key.WithKeys("b"), key.WithHelp("b", "switch branch")),
|
||||
key.NewBinding(key.WithKeys("x"), key.WithHelp("x", "restore")),
|
||||
}
|
||||
m := New(theme.Default(), keys)
|
||||
m.SetSize(36, 20)
|
||||
lines := m.palette()
|
||||
if len(lines) != 2 {
|
||||
t.Fatalf("want 2 lines, got %q", lines)
|
||||
}
|
||||
all := strings.Join(lines, "\n")
|
||||
for _, want := range []string{"copy path", "update pin", "switch branch", "x restore"} {
|
||||
if !strings.Contains(all, want) {
|
||||
t.Errorf("palette lacks %q: %q", want, lines)
|
||||
}
|
||||
}
|
||||
for _, l := range lines {
|
||||
if w := lipgloss.Width(l); w > 36 {
|
||||
t.Errorf("line %q is %d wide", l, w)
|
||||
}
|
||||
}
|
||||
m.SetSize(120, 20)
|
||||
if lines := m.palette(); len(lines) != 1 {
|
||||
t.Errorf("wide pane: want 1 line, got %q", lines)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user