After d or g, the context line lists what may follow (d cut rows, t next sheet); the command line's completion box is as wide as its entries.
- commit
- 116aa5efb01bc908948f9a62362ebe54ba869b35
- parent
- 67089f72a65bfcb7c31a992ac5282fe0a70a32bf
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 3 | ++- |
| M | internal/ | 37 | ++++++++++++++++++++++++++++-- |
@@ -307,7 +307,6 @@ func (c *cmdLine) layout(m *Model) []box {
307307 return nil308308 }309309 c.show(rows)310- inner := min(m.width-2, 72)311310 tw, ww, kw := 0, 0, 0312311 for _, it := range c.shown {313312 tw = max(tw, ansi.StringWidth(it.title))@@ -316,6 +315,8 @@ func (c *cmdLine) layout(m *Model) []box {
316315 kw = max(kw, ansi.StringWidth(it.key)+2)317316 }318317 }318+ // As wide as the completions, within the screen and a line's reach.319+ inner := min(max(1+tw+2+ww+2+kw+1, 40), 72, m.width-2)319320 tw = min(tw, inner/2)320321 ww = max(min(ww, inner-1-tw-2-kw-2), 0)321322 lines := make([]string, rows)@@ -1,6 +1,7 @@
11 package ui22 33 import (4+ "slices"45 "strconv"56 "strings"67 @@ -250,10 +251,11 @@ var vimMotions = map[string]motion{
250251 }251252 252253 // vimLine is the context line while a sequence is being typed (the keys253-// so far, as vim's showcmd) or in VISUAL mode (what applies).254+// so far, as vim's showcmd, and the keys that finish it) or in VISUAL255+// mode (what applies).254256 func (m *Model) vimLine() string {255257 if p := m.vim.pending(); p != "" {256- return m.th.Key.Render(p) + m.th.Muted.Render(" ") + m.th.KeyHints("Esc", "cancel")258+ return m.th.Key.Render(p) + " " + m.th.KeyHints(append(m.vimNext(), "Esc", "cancel")...)257259 }258260 if m.vim.visual == visualRows {259261 return m.th.KeyHints("d", "delete rows", "y", "copy rows", "o", "other end", ":", "command", "Esc", "back")@@ -261,6 +263,37 @@ func (m *Model) vimLine() string {
261263 return m.th.KeyHints("d", "delete", "y", "copy", "p", "paste", "o", "other corner", "V", "rows", "Esc", "back")262264 }263265 266+// vimNext lists the keys that finish the sequence begun, and what they267+// do, as pairs for KeyHints: after d, "d" and "cut rows".268+func (m *Model) vimNext() []string {269+ if m.vim.keys == "" {270+ return nil // just a count: anything may follow271+ }272+ table := vimNormal273+ if m.visual() != visualNone {274+ table = vimVisual275+ }276+ var seqs []string277+ for seq := range table {278+ if len(seq) > len(m.vim.keys) && strings.HasPrefix(seq, m.vim.keys) {279+ seqs = append(seqs, seq)280+ }281+ }282+ if m.vim.keys == "g" {283+ seqs = append(seqs, "gg")284+ }285+ slices.Sort(seqs)286+ var out []string287+ for _, seq := range seqs {288+ what := "first row"289+ if b, ok := table[seq]; ok {290+ what = strings.ToLower(commands[b.id].title)291+ }292+ out = append(out, seq[len(m.vim.keys):], what)293+ }294+ return out295+}296+264297 // startVisual selects from the active cell: cells, or whole rows.265298 func (m *Model) startVisual(kind visualKind) {266299 if m.visual() == visualNone {