From 5d38c91bc1815c3c953e23a4e2fee9814c751d38 Mon Sep 17 00:00:00 2001 From: meep Date: Sun, 11 Apr 2021 16:36:25 +0200 Subject: [PATCH] Various unseen changes to fuzzy completions --- src/completions.ts | 18 ++++++++++++------ src/completions/Tab.ts | 12 ++++++------ src/completions/TabAll.ts | 8 ++++---- src/excmds.ts | 25 ++++++++++++++++++++++++- src/lib/config.ts | 7 +++---- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/completions.ts b/src/completions.ts index f830a477..0f4f1210 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -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`
` @@ -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, diff --git a/src/completions/Tab.ts b/src/completions/Tab.ts index ec13adc5..dd413448 100644 --- a/src/completions/Tab.ts +++ b/src/completions/Tab.ts @@ -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` @@ -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 */ diff --git a/src/completions/TabAll.ts b/src/completions/TabAll.ts index 734fe5db..50a71c67 100644 --- a/src/completions/TabAll.ts +++ b/src/completions/TabAll.ts @@ -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()) } diff --git a/src/excmds.ts b/src/excmds.ts index a4daf918..7212a778 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -3458,7 +3458,30 @@ export async function yankimage(url: string): Promise { "#" 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.
+ + White space acts as an AND operator, while a single pipe (|) character acts as an OR operator.
+ To escape white space, use double quote ex. ="scheme language" for exact match.
+ + Each word can be prefixed with an extended search token, otherwise it will be fuzzy matched.
+ All combinations possible, results ordered via scoring against all Tokens & Fuzzyness Factor.
+ + | Token | Match type | Description
| + |:-----------|:------------------------------:|--------------------------------------:| + | 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).
+ 0.1 "almost" only hits exact matches,
+ 0.3 "some" minor typos, missing chars also hit (default)
+ Higher values if u have no clue what you are searching for...
+ */ //#background export async function tab(...id: string[]) { diff --git a/src/lib/config.ts b/src/lib/config.ts index 63d9ed1c..569c41e8 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -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 = {