Hide already typed keys inside showbinds menu (#2249)
This commit is contained in:
1 parent
c19e3a68c1
commit
0283b2a71a
3 files changed
+31
-21
No files matched your search
+1
-1
@@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|||||||
- The string representation of commands shown when displaying keybindings is simplified (e.g. `cd ~` instead of `cd -- [~]`) (#2165).
|
- The string representation of commands shown when displaying keybindings is simplified (e.g. `cd ~` instead of `cd -- [~]`) (#2165).
|
||||||
- `yes-no-prompts` now use the same design everywhere (#2212).
|
- `yes-no-prompts` now use the same design everywhere (#2212).
|
||||||
- Logs generated by `-log <path>` now get appended to `<path>` instead of overwriting it (#2215).
|
- Logs generated by `-log <path>` now get appended to `<path>` instead of overwriting it (#2215).
|
||||||
- The `showbinds` menu no longer shows an unnecessary `mode` column (#2226) (#2228).
|
- The `showbinds` menu now hides the redundant `mode` column (#2226) (#2228) and omits already typed keys (#2249).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|||||||
@@ -564,16 +564,16 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
gState.data["maps"] = listBinds(map[string]map[string]expr{
|
gState.data["maps"] = listBinds(map[string]map[string]expr{
|
||||||
"n": gOpts.nkeys,
|
"n": gOpts.nkeys,
|
||||||
"v": gOpts.vkeys,
|
"v": gOpts.vkeys,
|
||||||
}, true)
|
})
|
||||||
gState.data["nmaps"] = listBinds(map[string]map[string]expr{
|
gState.data["nmaps"] = listBinds(map[string]map[string]expr{
|
||||||
"n": gOpts.nkeys,
|
"n": gOpts.nkeys,
|
||||||
}, true)
|
})
|
||||||
gState.data["vmaps"] = listBinds(map[string]map[string]expr{
|
gState.data["vmaps"] = listBinds(map[string]map[string]expr{
|
||||||
"v": gOpts.vkeys,
|
"v": gOpts.vkeys,
|
||||||
}, true)
|
})
|
||||||
gState.data["cmaps"] = listBinds(map[string]map[string]expr{
|
gState.data["cmaps"] = listBinds(map[string]map[string]expr{
|
||||||
"c": gOpts.cmdkeys,
|
"c": gOpts.cmdkeys,
|
||||||
}, true)
|
})
|
||||||
gState.data["cmds"] = listCmds(gOpts.cmds)
|
gState.data["cmds"] = listCmds(gOpts.cmds)
|
||||||
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
|
gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd)
|
||||||
gState.data["history"] = listHistory(app.cmdHistory)
|
gState.data["history"] = listHistory(app.cmdHistory)
|
||||||
|
|||||||
@@ -1315,7 +1315,7 @@ func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func listBinds(binds map[string]map[string]expr, showMode bool) string {
|
func listBinds(binds map[string]map[string]expr) string {
|
||||||
t := new(tabwriter.Writer)
|
t := new(tabwriter.Writer)
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
@@ -1352,17 +1352,30 @@ func listBinds(binds map[string]map[string]expr, showMode bool) string {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
|
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
|
||||||
|
fmt.Fprintln(t, "mode\tkey\tcommand")
|
||||||
|
for _, e := range entries {
|
||||||
|
fmt.Fprintf(t, "%s\t%s\t%s\n", e.mode, e.key, e.cmd)
|
||||||
|
}
|
||||||
|
t.Flush()
|
||||||
|
|
||||||
if showMode {
|
return b.String()
|
||||||
fmt.Fprintln(t, "mode\tkeys\tcommand")
|
}
|
||||||
for _, e := range entries {
|
|
||||||
fmt.Fprintf(t, "%s\t%s\t%s\n", e.mode, e.key, e.cmd)
|
func listMatchingBinds(binds map[string]expr, prefix string) string {
|
||||||
}
|
t := new(tabwriter.Writer)
|
||||||
} else {
|
b := new(bytes.Buffer)
|
||||||
fmt.Fprintln(t, "keys\tcommand")
|
|
||||||
for _, e := range entries {
|
keys := make([]string, 0, len(binds))
|
||||||
fmt.Fprintf(t, "%s\t%s\n", e.key, e.cmd)
|
for k := range binds {
|
||||||
}
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
|
||||||
|
fmt.Fprintln(t, "key\tcommand")
|
||||||
|
for _, k := range keys {
|
||||||
|
remain, _ := strings.CutPrefix(k, prefix)
|
||||||
|
fmt.Fprintf(t, "%s\t%v\n", remain, binds[k])
|
||||||
}
|
}
|
||||||
t.Flush()
|
t.Flush()
|
||||||
|
|
||||||
@@ -1540,10 +1553,8 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
keys := gOpts.nkeys
|
keys := gOpts.nkeys
|
||||||
mode := "n"
|
|
||||||
if nav.isVisualMode() {
|
if nav.isVisualMode() {
|
||||||
keys = gOpts.vkeys
|
keys = gOpts.vkeys
|
||||||
mode = "v"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch tev := ev.(type) {
|
switch tev := ev.(type) {
|
||||||
@@ -1619,9 +1630,8 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
return expr
|
return expr
|
||||||
}
|
}
|
||||||
if gOpts.showbinds {
|
if gOpts.showbinds {
|
||||||
ui.menu = listBinds(map[string]map[string]expr{
|
// mode and already typed keys are obvious here; no need to clutter the menu
|
||||||
mode: binds,
|
ui.menu = listMatchingBinds(binds, string(ui.keyAcc))
|
||||||
}, false) // mode is obvious here; no need to clutter the menu
|
|
||||||
}
|
}
|
||||||
return draw
|
return draw
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user