Skip to content

Commit

Permalink
Fixed bug whereby inline suggestion filtering was not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglev committed Jun 28, 2022
1 parent 0f6cf45 commit 7db0653
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ const DEFAULT_SETTINGS: RedirectPluginSettings = {
const getRedirectFiles = (
plugin: RedirectPlugin,
files: TFile[],
filterString?: string,
limitToRedirectedFiles?: boolean
limitToRedirectedFiles: boolean,
filterString?: string
) => {
let redirectsGathered = files
.map((file) => {
const frontMatter =
plugin.app.metadataCache.getFileCache(file)?.frontmatter;
const aliases = frontMatter?.alias || frontMatter?.aliases || [];
const redirects =
frontMatter?.redirects || frontMatter?.redirect || [];
frontMatter?.redirects ||
frontMatter?.redirect ||
(limitToRedirectedFiles ? [] : [file.basename]);
let output = [
...(Array.isArray(aliases) ? aliases : [aliases]),
file.basename,
Expand Down Expand Up @@ -129,6 +131,7 @@ const getRedirectFiles = (
const queryWords = filterString
.toLowerCase()
.split(/\s{1,}/);

return queryWords.every((word) => {
return (
a.alias.toLowerCase().contains(word) ||
Expand All @@ -137,20 +140,6 @@ const getRedirectFiles = (
});
});

if (output.length === 0 && limitToRedirectedFiles !== true) {
output = [
{
alias: `${file.path}`,
path: `${file.path}`,
originTFile: file,
embedPath: plugin.app.vault.getResourcePath(file),
isAlias: false,
extension: file.extension,
redirectTFile: file,
},
];
}

return output;
})
.filter((a) => a.length)
Expand Down Expand Up @@ -212,7 +201,11 @@ const handleFilesWithModal = (
files: FileWithPath[] | TFile[],
ctrlKey: boolean
) => {
const redirectFiles = getRedirectFiles(plugin, app.vault.getFiles());
const redirectFiles = getRedirectFiles(
plugin,
app.vault.getFiles(),
plugin.settings.limitToRedirectedFiles
);

[...files].forEach((f: FileWithPath | TFile) => {
let filePath = f.path;
Expand Down Expand Up @@ -366,7 +359,11 @@ export default class RedirectPlugin extends Plugin {
.openFile(file.redirectTFile);
},
limitToNonMarkdown: this.settings.limitToNonMarkdown,
files: getRedirectFiles(this, app.vault.getFiles()),
files: getRedirectFiles(
this,
app.vault.getFiles(),
this.settings.limitToRedirectedFiles
),
});
fileModal.open();
},
Expand All @@ -389,7 +386,11 @@ export default class RedirectPlugin extends Plugin {
.openFile(file.originTFile);
},
limitToNonMarkdown: this.settings.limitToNonMarkdown,
files: getRedirectFiles(this, app.vault.getFiles()),
files: getRedirectFiles(
this,
app.vault.getFiles(),
this.settings.limitToRedirectedFiles
),
});
fileModal.open();
},
Expand Down Expand Up @@ -622,6 +623,7 @@ class RedirectEditorSuggester extends EditorSuggest<{
return getRedirectFiles(
this.plugin,
this.plugin.app.vault.getFiles(),
this.plugin.settings.limitToRedirectedFiles,
context.query
);
}
Expand Down

0 comments on commit 7db0653

Please sign in to comment.