mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
completions: improve buffer index logic
This commit is contained in:
parent
5fe6068b4a
commit
b2dcbc7ff3
1 changed files with 13 additions and 9 deletions
|
@ -622,17 +622,21 @@ export class BufferCompletionSource extends CompletionSourceFuse {
|
|||
super.setStateFromScore(scoredOpts, true)
|
||||
}
|
||||
|
||||
/** Score with fuse unless query is an integer or a single # */
|
||||
/** Score with fuse unless query is a single # or looks like a buffer index */
|
||||
scoredOptions(query: string, options = this.options): ScoredOption[] {
|
||||
const args = query.split(/\s+/gu)
|
||||
if (args.length <= 2) {
|
||||
const args = query.trim().split(/\s+/gu)
|
||||
if (args.length === 1) {
|
||||
// if query is an integer n and |n| < options.length
|
||||
if (Number.isInteger(Number(args[0]))) {
|
||||
const index = (Number(args[0]) - 1).mod(options.length)
|
||||
let index = Number(args[0]) - 1
|
||||
if (Math.abs(index) < options.length) {
|
||||
index = index.mod(options.length)
|
||||
return [{
|
||||
index,
|
||||
option: options[index],
|
||||
score: 0,
|
||||
}]
|
||||
}
|
||||
} else if (args[0] === '#') {
|
||||
for (const [index, option] of enumerate(options)) {
|
||||
if (option.isAlternative) {
|
||||
|
|
Loading…
Add table
Reference in a new issue