mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
Merge pull request #2230 from mozbugbox/buffer-completion-number-prefix
Buffer completion with number prefix. close #2010.
This commit is contained in:
commit
a12dd78fe8
1 changed files with 23 additions and 1 deletions
|
@ -102,7 +102,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
if (Math.abs(index) < options.length) {
|
||||
index = index.mod(options.length)
|
||||
// options order might change by scored sorting
|
||||
return this.nthTabscoredOptions(index, options)
|
||||
return this.TabscoredOptionsStartsWithN(index, options)
|
||||
}
|
||||
} else if (args[0] === "#") {
|
||||
for (const [index, option] of enumerate(options)) {
|
||||
|
@ -139,6 +139,28 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
}
|
||||
}
|
||||
|
||||
/** Return the scoredOption[] result for the tab index startswith n */
|
||||
private TabscoredOptionsStartsWithN(
|
||||
n: number,
|
||||
options: BufferCompletionOption[]
|
||||
): Completions.ScoredOption[] {
|
||||
const nstr = (n + 1).toString()
|
||||
const res = [];
|
||||
for (const [index, option] of enumerate(options)) {
|
||||
if ((option.tabIndex + 1).toString().startsWith(nstr)) {
|
||||
res.push({
|
||||
index, // index is not tabIndex, changed by score
|
||||
option,
|
||||
score: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// old input will change order: 12 => 123 => 12
|
||||
res.sort((a, b) => a.option.tabIndex - b.option.tabIndex)
|
||||
return res;
|
||||
}
|
||||
|
||||
private async fillOptions() {
|
||||
const tabs: browser.tabs.Tab[] = await browserBg.tabs.query({
|
||||
currentWindow: true,
|
||||
|
|
Loading…
Add table
Reference in a new issue