Skip to content

Commit

Permalink
If no other candidates besides 'Internal link' are displayed, and if …
Browse files Browse the repository at this point in the history
…'partial match fallback' does not yield results, then immediately proceed to 'new link fallback' #292
  • Loading branch information
tadashi-aikawa committed Mar 23, 2024
1 parent 554b0cb commit 22cc03a
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/ui/AutoCompleteSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,28 +394,29 @@ export class AutoCompleteSuggest
}[];
};

const createNewLinkSuggestions = (): Word[] =>
parsedQuery.queries
.slice()
.reverse()
.filter((q) => q.word.length >= this.minNumberTriggered)
.map((q) => ({
value: q.word,
createdPath: "FIXME: ",
type: "internalLink",
phantom: true,
offset: q.offset,
}));

if (parsedQuery.completionMode === "new") {
cb(
parsedQuery.queries
.slice()
.reverse()
.filter((q) => q.word.length >= this.minNumberTriggered)
.map((q) => ({
value: q.word,
createdPath: "FIXME: ",
type: "internalLink",
phantom: true,
offset: q.offset,
})),
);
cb(createNewLinkSuggestions());
return;
}

const matchStrategy = MatchStrategy.fromName(
parsedQuery.completionMode,
);

const words = parsedQuery.queries
let words = parsedQuery.queries
.filter(
(x, i, xs) =>
parsedQuery.currentFrontMatter ||
Expand Down Expand Up @@ -449,6 +450,18 @@ export class AutoCompleteSuggest
.flat()
.sort((a, b) => Number(a.fuzzy) - Number(b.fuzzy));

// Fallback linkify and partial completion mode
if (
this.completionMode != this.matchStrategy.name &&
this.completionMode === "partial"
) {
words = words.filter((x) => x.type === "internalLink");
if (words.length === 0) {
cb(createNewLinkSuggestions());
return;
}
}

cb(
uniqWith(words, suggestionUniqPredicate).slice(
0,
Expand Down

0 comments on commit 22cc03a

Please sign in to comment.