mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Add completion options for all binds
This commit is contained in:
parent
a39e45cabb
commit
f9380c2439
2 changed files with 73 additions and 34 deletions
|
@ -2,8 +2,10 @@ import * as Completions from "@src/completions"
|
|||
import * as Metadata from "@src/.metadata.generated"
|
||||
import * as aliases from "@src/lib/aliases"
|
||||
import * as config from "@src/lib/config"
|
||||
import { mode2maps } from "@src/lib/binding"
|
||||
|
||||
class AproposCompletionOption extends Completions.CompletionOptionHTML
|
||||
class AproposCompletionOption
|
||||
extends Completions.CompletionOptionHTML
|
||||
implements Completions.CompletionOptionFuse {
|
||||
public fuseKeys = []
|
||||
|
||||
|
@ -48,11 +50,44 @@ export class AproposCompletionSource extends Completions.CompletionSourceFuse {
|
|||
const fns = excmds.getFunctions()
|
||||
const settings = config.get()
|
||||
const exaliases = settings.exaliases
|
||||
const bindings = settings.nmaps
|
||||
const allbindings = {}
|
||||
|
||||
for (const [key, value] of mode2maps.entries()) {
|
||||
allbindings[key] = settings[value]
|
||||
}
|
||||
|
||||
function query2bindcompletions(options, query) {
|
||||
const modenames = Object.keys(allbindings)
|
||||
const completions = []
|
||||
for (const modename of modenames) {
|
||||
const binds = Object.keys(
|
||||
allbindings[modename],
|
||||
).filter(binding =>
|
||||
(binding + allbindings[modename][binding])
|
||||
.toLowerCase()
|
||||
.includes(query),
|
||||
)
|
||||
for (const binding of binds) {
|
||||
completions.push(
|
||||
new AproposCompletionOption(
|
||||
binding,
|
||||
`${
|
||||
modename[0].toUpperCase() + modename.slice(1)
|
||||
} mode binding for \`${
|
||||
allbindings[modename][binding]
|
||||
}\``,
|
||||
"-b",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
if (
|
||||
fns === undefined ||
|
||||
exaliases === undefined ||
|
||||
bindings === undefined
|
||||
settings.nmaps === undefined
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
@ -83,22 +118,7 @@ export class AproposCompletionSource extends Completions.CompletionSourceFuse {
|
|||
}),
|
||||
),
|
||||
"-b": (options, query) =>
|
||||
options.concat(
|
||||
Object.keys(bindings)
|
||||
.filter(binding =>
|
||||
(binding + bindings[binding])
|
||||
.toLowerCase()
|
||||
.includes(query),
|
||||
)
|
||||
.map(
|
||||
binding =>
|
||||
new AproposCompletionOption(
|
||||
binding,
|
||||
`Normal mode binding for \`${bindings[binding]}\``,
|
||||
"-b",
|
||||
),
|
||||
),
|
||||
),
|
||||
options.concat(query2bindcompletions(options, query)),
|
||||
"-e": (options, query) =>
|
||||
options.concat(
|
||||
fns
|
||||
|
|
|
@ -2,8 +2,10 @@ import * as Completions from "@src/completions"
|
|||
import * as Metadata from "@src/.metadata.generated"
|
||||
import * as aliases from "@src/lib/aliases"
|
||||
import * as config from "@src/lib/config"
|
||||
import { mode2maps } from "@src/lib/binding"
|
||||
|
||||
class HelpCompletionOption extends Completions.CompletionOptionHTML
|
||||
class HelpCompletionOption
|
||||
extends Completions.CompletionOptionHTML
|
||||
implements Completions.CompletionOptionFuse {
|
||||
public fuseKeys = []
|
||||
|
||||
|
@ -48,11 +50,39 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
const fns = excmds.getFunctions()
|
||||
const settings = config.get()
|
||||
const exaliases = settings.exaliases
|
||||
const bindings = settings.nmaps
|
||||
const allbindings = {}
|
||||
for (const [key, value] of mode2maps.entries()) {
|
||||
allbindings[key] = settings[value]
|
||||
}
|
||||
|
||||
function query2bindcompletions(options, query) {
|
||||
const modenames = Object.keys(allbindings)
|
||||
const completions = []
|
||||
for (const modename of modenames) {
|
||||
const binds = Object.keys(
|
||||
allbindings[modename],
|
||||
).filter(binding => binding.startsWith(query))
|
||||
for (const binding of binds) {
|
||||
completions.push(
|
||||
new HelpCompletionOption(
|
||||
binding,
|
||||
`${
|
||||
modename[0].toUpperCase() + modename.slice(1)
|
||||
} mode binding for \`${
|
||||
allbindings[modename][binding]
|
||||
}\``,
|
||||
"-b",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
if (
|
||||
fns === undefined ||
|
||||
exaliases === undefined ||
|
||||
bindings === undefined
|
||||
settings.nmaps === undefined
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
@ -75,18 +105,7 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
}),
|
||||
),
|
||||
"-b": (options, query) =>
|
||||
options.concat(
|
||||
Object.keys(bindings)
|
||||
.filter(binding => binding.startsWith(query))
|
||||
.map(
|
||||
binding =>
|
||||
new HelpCompletionOption(
|
||||
binding,
|
||||
`Normal mode binding for \`${bindings[binding]}\``,
|
||||
"-b",
|
||||
),
|
||||
),
|
||||
),
|
||||
options.concat(query2bindcompletions(options, query)),
|
||||
"-e": (options, query) =>
|
||||
options.concat(
|
||||
fns
|
||||
|
|
Loading…
Add table
Reference in a new issue