completions: improve buffer index logic

This commit is contained in:
Colin Caine 2017-12-28 17:07:07 +00:00
parent 5fe6068b4a
commit b2dcbc7ff3

View file

@ -622,17 +622,21 @@ export class BufferCompletionSource extends CompletionSourceFuse {
super.setStateFromScore(scoredOpts, true) 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[] { scoredOptions(query: string, options = this.options): ScoredOption[] {
const args = query.split(/\s+/gu) const args = query.trim().split(/\s+/gu)
if (args.length <= 2) { if (args.length === 1) {
// if query is an integer n and |n| < options.length
if (Number.isInteger(Number(args[0]))) { 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 [{ return [{
index, index,
option: options[index], option: options[index],
score: 0, score: 0,
}] }]
}
} else if (args[0] === '#') { } else if (args[0] === '#') {
for (const [index, option] of enumerate(options)) { for (const [index, option] of enumerate(options)) {
if (option.isAlternative) { if (option.isAlternative) {