Skip to content

Commit

Permalink
Add a to property to completion results
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Aug 9, 2024
1 parent bd33cb5 commit ca6b7dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions package/src/extensions/autocomplete/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const autoComplete =
let isTyping: boolean
let isOpen: boolean
let shouldOpen: boolean
let currentOptions: [number, number[], number, Completion][]
let currentOptions: [number, number[], number, number, Completion][]
let numOptions: number
let activeIndex: number
let active: HTMLLIElement | undefined
Expand Down Expand Up @@ -98,7 +98,7 @@ const autoComplete =
const updateRow = (index: number) => {
const option = currentOptions[index + offset]
const [iconEl, labelEl, detailsEl] = rows[index].children as HTMLCollectionOf<HTMLDivElement>
const completion = option[3]
const completion = option[4]
const icon = completion.icon || "variable"

updateMatched(labelEl, option[1], completion.label)
Expand Down Expand Up @@ -141,7 +141,7 @@ const autoComplete =
}

const insertOption = (index: number) => {
let [, , start, completion] = currentOptions[index]
let [, , start, end, completion] = currentOptions[index]
let { label, tabStops: tabStops = [], insert } = completion
let l = tabStops.length
tabStops = tabStops.map(stop => stop + start)
Expand All @@ -166,7 +166,7 @@ const autoComplete =

if (l % 2) tabStops[l] = tabStops[l - 1]

insertText(editor, insert, start, pos, tabStops[0], tabStops[1])
insertText(editor, insert, start, end, tabStops[0], tabStops[1])

if (l > 2) {
stops = tabStops
Expand Down Expand Up @@ -227,7 +227,7 @@ const autoComplete =
if (filterResult) {
filterResult[0] += option.boost || 0
// @ts-expect-error Allow mutation
filterResult.push(from, option)
filterResult.push(from, result.to ?? pos, option)
// @ts-expect-error Allow mutation
currentOptions.push(filterResult)
}
Expand All @@ -236,7 +236,7 @@ const autoComplete =
})

if (currentOptions[0]) {
currentOptions.sort((a, b) => b[0] - a[0] || a[3].label.localeCompare(b[3].label))
currentOptions.sort((a, b) => b[0] - a[0] || a[4].label.localeCompare(b[4].label))
numOptions = currentOptions.length
activeIndex = offset = 0

Expand Down
6 changes: 6 additions & 0 deletions package/src/extensions/autocomplete/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export interface Completion {
export interface CompletionResult {
/** The start of the range that's being completed. */
from: number
/**
* The end of the range that will be replaced when one of the options is selected.
* This is not used when sorting or filtering the options. Defaults to the cursor's
* position.
*/
to?: number
/** The completions returned by the source. */
options: Completion[]
}
Expand Down

0 comments on commit ca6b7dd

Please # to comment.