Fix #2761: canonicalise aliases in completions

This commit is contained in:
Oliver Blanthorn 2026-07-22 10:18:28 +02:00
parent b5f2ab64c5
commit eabaecc548
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
11 changed files with 15 additions and 24 deletions

View file

@ -59,6 +59,10 @@ export abstract class CompletionSource {
this.trailingSpace = options.trailingSpace
}
protected canonicalisePrefix(prefix: string) {
return aliases.expandExstr(prefix).trim()
}
/** Control presentation of Source */
set state(newstate: OptionState) {
switch (newstate) {

View file

@ -59,7 +59,8 @@ export class AutocmdCompletionSource extends Completions.CompletionSourceFuse {
this.state = "hidden"
return
}
const is_autocmddelete = /del/.test(prefix)
const is_autocmddelete =
this.canonicalisePrefix(prefix) === "autocmddelete"
const filter_defined_autocmds = is_autocmddelete
const defined_autocmds = config.get("autocmds")
// Config may contain empty dictionnaries if user deleted all patterns

View file

@ -51,6 +51,7 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
this.state = "hidden"
return
}
prefix = this.canonicalisePrefix(prefix)
this.deselect()

View file

@ -96,17 +96,6 @@ export class BmarkCompletionSource extends Completions.CompletionSourceFuse {
// Call concrete class
return this.updateDisplay()
}
select(option: Completions.CompletionOption) {
if (this.lastExstr !== undefined && option !== undefined) {
this.completion = "bmarks " + option.value
this.args = option.value
option.state = "focused"
this.lastFocused = option
} else {
throw new Error("lastExstr and option must be defined!")
}
}
}
export class BookmarkFolderCompletionSource extends Completions.CompletionSourceFuse {

View file

@ -5,7 +5,6 @@ import * as config from "@src/lib/config"
import * as aliases from "@src/lib/aliases"
const PREFIX = "composite"
const regex = new RegExp("^" + PREFIX + " ")
// Most of this is copied verbatim from Excmd.ts - would have liked to inherit but constructor posed difficulties
export class CompositeCompletionSource extends Completions.CompletionSourceFuse {
@ -121,8 +120,8 @@ export class CompositeCompletionSource extends Completions.CompletionSourceFuse
}
private getendexstr(exstr) {
return exstr
.replace(regex, "")
const [, query = exstr] = this.splitOnPrefix(exstr)
return query
.split("|")
.slice(-1)[0]
.split(";")

View file

@ -61,12 +61,6 @@ export class ExtensionsCompletionSource extends Completions.CompletionSourceFuse
return this.updateDisplay()
}
select(option: ExtensionsCompletionOption) {
this.completion = "extoptions " + option.name
option.state = "focused"
this.lastFocused = option
}
private scoreOptions(options: ExtensionsCompletionOption[]) {
return options.sort((o1, o2) => o1.name.localeCompare(o2.name))
}

View file

@ -72,6 +72,7 @@ export class HistoryCompletionSource extends Completions.CompletionSourceFuse {
}
const headerPostfix = []
prefix = this.canonicalisePrefix(prefix)
// Ignoring command-specific arguments
// It's terrible but it's ok because it's just a stopgap until an actual commandline-parsing API is implemented

View file

@ -52,6 +52,7 @@ export class SettingsCompletionSource extends Completions.CompletionSourceFuse {
this.state = "hidden"
return
}
prefix = this.canonicalisePrefix(prefix)
// Ignoring command-specific arguments
// It's terrible but it's ok because it's just a stopgap until an actual commandline-parsing API is implemented

View file

@ -227,7 +227,8 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
@Perf.measuredAsync
private async updateOptions(exstr = "") {
this.lastExstr = exstr
const [prefix, query] = this.splitOnPrefix(exstr)
let [prefix, query] = this.splitOnPrefix(exstr)
if (prefix) prefix = this.canonicalisePrefix(prefix)
this.shouldSetStateFromScore =
config.get("completions", "Tab", "autoselect") === "true" &&
prefix !== "tabrename" &&

View file

@ -199,7 +199,7 @@ export class TabAllCompletionSource extends Completions.CompletionSourceFuse {
// Check to see if this is a command that needs to exclude the current
// window
const excludeCurrentWindow = ["tabgrab"].includes(prefix.trim())
const excludeCurrentWindow = this.canonicalisePrefix(prefix) === "tabgrab"
const currentWindow = await browserBg.windows.getCurrent()
// Window Ids don't make sense so we're using LASTID and WININDEX to compute a window index
// This relies on the fact that tabs are sorted by window ids

View file

@ -69,7 +69,7 @@ export class WindowCompletionSource extends Completions.CompletionSourceFuse {
return
}
const excludeCurrentWindow = ["tabpush"].includes(prefix.trim())
const excludeCurrentWindow = this.canonicalisePrefix(prefix) === "tabpush"
this.options = (await browserBg.windows.getAll({ populate: true }))
.filter( win => !(excludeCurrentWindow && win.focused))
.map(