mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Various unseen changes to fuzzy completions
This commit is contained in:
parent
5db0337349
commit
5d38c91bc1
5 changed files with 49 additions and 21 deletions
|
@ -160,8 +160,10 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
findAllMatches: true,
|
findAllMatches: true,
|
||||||
ignoreLocation: true,
|
ignoreLocation: true,
|
||||||
threshold: config.get("completionfuzziness"),
|
threshold: config.get("fuzzy_threshold"),
|
||||||
minMatchCharLength: 1,
|
ignoreFieldNorm: true,
|
||||||
|
useExtendedSearch: false,
|
||||||
|
// minMatchCharLength: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
// PERF: Could be expensive not to cache Fuse()
|
// PERF: Could be expensive not to cache Fuse()
|
||||||
|
@ -169,7 +171,7 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
||||||
fuse = undefined
|
fuse = undefined
|
||||||
|
|
||||||
protected lastExstr: string
|
protected lastExstr: string
|
||||||
protected sortScoredOptions = false
|
protected sortScoredOptions = true
|
||||||
|
|
||||||
protected optionContainer = html`<table class="optionContainer"></table>`
|
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
|
// Filter by query if query is not empty
|
||||||
if (query) {
|
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 show all options
|
||||||
} else {
|
} else {
|
||||||
options.forEach(option => (option.state = "normal"))
|
options.forEach(option => (option.state = "normal"))
|
||||||
|
@ -246,14 +251,15 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rtn sorted array of {option, score} */
|
/** Rtn sorted array of {option, score} */
|
||||||
scoredOptions(query: string): ScoredOption[] {
|
scoredOptions(query: string, extended = false): ScoredOption[] {
|
||||||
const searchThis = this.options.map((elem, index) => ({
|
const searchThis = this.options.map((elem, index) => ({
|
||||||
index,
|
index,
|
||||||
fuseKeys: elem.fuseKeys,
|
fuseKeys: elem.fuseKeys,
|
||||||
}))
|
}))
|
||||||
|
this.fuseOptions.useExtendedSearch = extended
|
||||||
this.fuse = new Fuse(searchThis, this.fuseOptions)
|
this.fuse = new Fuse(searchThis, this.fuseOptions)
|
||||||
return this.fuse.search(query).map(result => {
|
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)
|
const index = toNumber(result.item.index)
|
||||||
return {
|
return {
|
||||||
index,
|
index,
|
||||||
|
|
|
@ -43,9 +43,7 @@ class BufferCompletionOption
|
||||||
const favIconUrl = tab.favIconUrl
|
const favIconUrl = tab.favIconUrl
|
||||||
? tab.favIconUrl
|
? tab.favIconUrl
|
||||||
: Completions.DEFAULT_FAVICON
|
: Completions.DEFAULT_FAVICON
|
||||||
const indicator = tab.audible
|
// const indicator = tab.audible ? String.fromCodePoint(0x1f50a) : ""
|
||||||
? String.fromCodePoint(0x1F50A)
|
|
||||||
: ""
|
|
||||||
this.html = html`<tr
|
this.html = html`<tr
|
||||||
class="BufferCompletionOption option container_${container.color} container_${container.icon} container_${container.name}"
|
class="BufferCompletionOption option container_${container.color} container_${container.icon} container_${container.name}"
|
||||||
>
|
>
|
||||||
|
@ -76,8 +74,9 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
"Tabs",
|
"Tabs",
|
||||||
)
|
)
|
||||||
this.sortScoredOptions = true
|
this.sortScoredOptions = true
|
||||||
this.shouldSetStateFromScore =
|
this.shouldSetStateFromScore = false
|
||||||
config.get("completions", "Tab", "autoselect") === "true"
|
// autoselect after space sucks for (fuzzy-) searching with multiple words
|
||||||
|
// config.get("completions", "Tab", "autoselect") === "true"
|
||||||
this.updateOptions()
|
this.updateOptions()
|
||||||
this._parent.appendChild(this.node)
|
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 */
|
/** Score with fuse unless query is a single # or looks like a tab index */
|
||||||
scoredOptions(
|
scoredOptions(
|
||||||
query: string,
|
query: string,
|
||||||
|
extended = true,
|
||||||
options = this.options,
|
options = this.options,
|
||||||
): Completions.ScoredOption[] {
|
): Completions.ScoredOption[] {
|
||||||
const args = query.trim().split(/\s+/gu)
|
const args = query.trim().split(/\s+/gu)
|
||||||
|
@ -130,7 +130,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not yet returned...
|
// If not yet returned...
|
||||||
return super.scoredOptions(query)
|
return super.scoredOptions(query, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the scoredOption[] result for the tab index startswith n */
|
/** Return the scoredOption[] result for the tab index startswith n */
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { browserBg } from "@src/lib/webext"
|
||||||
import * as Containers from "@src/lib/containers"
|
import * as Containers from "@src/lib/containers"
|
||||||
import * as Completions from "@src/completions"
|
import * as Completions from "@src/completions"
|
||||||
import * as Messaging from "@src/lib/messaging"
|
import * as Messaging from "@src/lib/messaging"
|
||||||
import * as config from "@src/lib/config"
|
// import * as config from "@src/lib/config"
|
||||||
|
|
||||||
class TabAllCompletionOption
|
class TabAllCompletionOption
|
||||||
extends Completions.CompletionOptionHTML
|
extends Completions.CompletionOptionHTML
|
||||||
|
@ -45,15 +45,15 @@ class TabAllCompletionOption
|
||||||
|
|
||||||
export class TabAllCompletionSource extends Completions.CompletionSourceFuse {
|
export class TabAllCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
public options: TabAllCompletionOption[]
|
public options: TabAllCompletionOption[]
|
||||||
private shouldSetStateFromScore = true
|
private shouldSetStateFromScore = false
|
||||||
|
|
||||||
constructor(private _parent) {
|
constructor(private _parent) {
|
||||||
super(["taball", "tabgrab"], "TabAllCompletionSource", "All Tabs")
|
super(["taball", "tabgrab"], "TabAllCompletionSource", "All Tabs")
|
||||||
|
|
||||||
this.updateOptions()
|
this.updateOptions()
|
||||||
this._parent.appendChild(this.node)
|
this._parent.appendChild(this.node)
|
||||||
this.shouldSetStateFromScore =
|
this.shouldSetStateFromScore = false
|
||||||
config.get("completions", "TabAll", "autoselect") === "true"
|
// config.get("completions", "TabAll", "autoselect") === "true"
|
||||||
|
|
||||||
Messaging.addListener("tab_changes", () => this.reactToTabChanges())
|
Messaging.addListener("tab_changes", () => this.reactToTabChanges())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3458,7 +3458,30 @@ export async function yankimage(url: string): Promise<void> {
|
||||||
|
|
||||||
"#" means the tab that was last accessed in this window
|
"#" 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
|
//#background
|
||||||
export async function tab(...id: string[]) {
|
export async function tab(...id: string[]) {
|
||||||
|
|
|
@ -1133,11 +1133,10 @@ export class default_config {
|
||||||
escapehatchsidebarhack: "true" | "false" = "true"
|
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.
|
* Threshold for fuzzy matching.
|
||||||
*
|
* lower == more strict
|
||||||
* https://fusejs.io/api/options.html#threshold
|
|
||||||
*/
|
*/
|
||||||
completionfuzziness = 0.3
|
fuzzy_threshold = 0.3
|
||||||
}
|
}
|
||||||
|
|
||||||
const platform_defaults = {
|
const platform_defaults = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue