Various unseen changes to fuzzy completions

This commit is contained in:
meep 2021-04-11 16:36:25 +02:00 committed by Oliver Blanthorn
parent 5db0337349
commit 5d38c91bc1
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
5 changed files with 49 additions and 21 deletions

View file

@ -160,8 +160,10 @@ export abstract class CompletionSourceFuse extends CompletionSource {
includeScore: true,
findAllMatches: true,
ignoreLocation: true,
threshold: config.get("completionfuzziness"),
minMatchCharLength: 1,
threshold: config.get("fuzzy_threshold"),
ignoreFieldNorm: true,
useExtendedSearch: false,
// minMatchCharLength: 3,
}
// PERF: Could be expensive not to cache Fuse()
@ -169,7 +171,7 @@ export abstract class CompletionSourceFuse extends CompletionSource {
fuse = undefined
protected lastExstr: string
protected sortScoredOptions = false
protected sortScoredOptions = true
protected optionContainer = html`<table class="optionContainer"></table>`
@ -213,7 +215,10 @@ export abstract class CompletionSourceFuse extends CompletionSource {
// Filter by query if query is not empty
if (query) {
this.setStateFromScore(this.scoredOptions(query))
this.setStateFromScore(
this.scoredOptions(query, prefix === "taball " ? true : false),
)
// this.setStateFromScore(this.scoredOptions(query))
// Else show all options
} else {
options.forEach(option => (option.state = "normal"))
@ -246,14 +251,15 @@ export abstract class CompletionSourceFuse extends CompletionSource {
}
/** Rtn sorted array of {option, score} */
scoredOptions(query: string): ScoredOption[] {
scoredOptions(query: string, extended = false): ScoredOption[] {
const searchThis = this.options.map((elem, index) => ({
index,
fuseKeys: elem.fuseKeys,
}))
this.fuseOptions.useExtendedSearch = extended
this.fuse = new Fuse(searchThis, this.fuseOptions)
return this.fuse.search(query).map(result => {
// console.log(result, result.item, query)
// console.log(result.item.index, result.score as number)
const index = toNumber(result.item.index)
return {
index,

View file

@ -43,9 +43,7 @@ class BufferCompletionOption
const favIconUrl = tab.favIconUrl
? tab.favIconUrl
: Completions.DEFAULT_FAVICON
const indicator = tab.audible
? String.fromCodePoint(0x1F50A)
: ""
// const indicator = tab.audible ? String.fromCodePoint(0x1f50a) : ""
this.html = html`<tr
class="BufferCompletionOption option container_${container.color} container_${container.icon} container_${container.name}"
>
@ -76,8 +74,9 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
"Tabs",
)
this.sortScoredOptions = true
this.shouldSetStateFromScore =
config.get("completions", "Tab", "autoselect") === "true"
this.shouldSetStateFromScore = false
// autoselect after space sucks for (fuzzy-) searching with multiple words
// config.get("completions", "Tab", "autoselect") === "true"
this.updateOptions()
this._parent.appendChild(this.node)
@ -102,6 +101,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
/** Score with fuse unless query is a single # or looks like a tab index */
scoredOptions(
query: string,
extended = true,
options = this.options,
): Completions.ScoredOption[] {
const args = query.trim().split(/\s+/gu)
@ -130,7 +130,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
}
// If not yet returned...
return super.scoredOptions(query)
return super.scoredOptions(query, true)
}
/** Return the scoredOption[] result for the tab index startswith n */

View file

@ -3,7 +3,7 @@ import { browserBg } from "@src/lib/webext"
import * as Containers from "@src/lib/containers"
import * as Completions from "@src/completions"
import * as Messaging from "@src/lib/messaging"
import * as config from "@src/lib/config"
// import * as config from "@src/lib/config"
class TabAllCompletionOption
extends Completions.CompletionOptionHTML
@ -45,15 +45,15 @@ class TabAllCompletionOption
export class TabAllCompletionSource extends Completions.CompletionSourceFuse {
public options: TabAllCompletionOption[]
private shouldSetStateFromScore = true
private shouldSetStateFromScore = false
constructor(private _parent) {
super(["taball", "tabgrab"], "TabAllCompletionSource", "All Tabs")
this.updateOptions()
this._parent.appendChild(this.node)
this.shouldSetStateFromScore =
config.get("completions", "TabAll", "autoselect") === "true"
this.shouldSetStateFromScore = false
// config.get("completions", "TabAll", "autoselect") === "true"
Messaging.addListener("tab_changes", () => this.reactToTabChanges())
}

View file

@ -3458,7 +3458,30 @@ export async function yankimage(url: string): Promise<void> {
"#" means the tab that was last accessed in this window
A non integer string means to search the URL and title for matches, in this window if called from tab, all windows if called from anytab. Title matches can contain '*' as a wildcard.
A non integer string means to search the URL and the TITLE for matches, in this window if called from tab, all windows if called from anytab.<br>
White space acts as an AND operator, while a single pipe (|) character acts as an OR operator.<br>
To escape white space, use double quote ex. ="scheme language" for exact match.<br>
Each word can be prefixed with an extended search token, otherwise it will be fuzzy matched.<br>
All combinations possible, results ordered via scoring against all Tokens & Fuzzyness Factor.<br>
| Token | Match type | Description<br>|
|:-----------|:------------------------------:|--------------------------------------:|
| jscript | fuzzy-match | Items that fuzzy match jscript|
| =scheme | exact-match | Items that are scheme|
| 'python | include-match | Items that include python|
| !ruby | inverse-exact-match | Items that do not include ruby|
| ^java | prefix-exact-match | Items that start with java|
| !^earlang | inverse-prefix-exact-match | Items that do not start with earlang|
| .js$ | suffix-exact-match | Items that end with .js|
| !.go$ | inverse-suffix-exact-match | Items that do not end with .go|
The Fuzzyness Factor cant be set via the "fuzzy_threshold" (value between 0 and 1).<br>
0.1 "almost" only hits exact matches, <br>
0.3 "some" minor typos, missing chars also hit (default)<br>
Higher values if u have no clue what you are searching for...<br>
*/
//#background
export async function tab(...id: string[]) {

View file

@ -1133,11 +1133,10 @@ export class default_config {
escapehatchsidebarhack: "true" | "false" = "true"
/**
* Threshold for fuzzy matching on completions. Lower => stricter matching. Range between 0 and 1: 0 corresponds to perfect matches only. 1 will match anything.
*
* https://fusejs.io/api/options.html#threshold
* Threshold for fuzzy matching.
* lower == more strict
*/
completionfuzziness = 0.3
fuzzy_threshold = 0.3
}
const platform_defaults = {