mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Fix find notes by path bug (#508)
This commit is contained in:
parent
9c0a56d70d
commit
526573f571
2 changed files with 43 additions and 8 deletions
32
src/utils.ts
32
src/utils.ts
|
|
@ -56,15 +56,30 @@ export const getNotesFromPath = async (
|
|||
return files;
|
||||
}
|
||||
|
||||
// Split the path to get the last folder name
|
||||
const pathSegments = path.split("/");
|
||||
const lastSegment = pathSegments[pathSegments.length - 1].toLowerCase();
|
||||
// Normalize the input path
|
||||
const normalizedPath = path.toLowerCase().replace(/^\/|\/$/g, "");
|
||||
|
||||
return files.filter((file) => {
|
||||
// Split the file path and get the last directory name
|
||||
return (
|
||||
isFolderMatch(file.path, lastSegment) || file.basename === lastSegment
|
||||
);
|
||||
// Normalize the file path
|
||||
const normalizedFilePath = file.path.toLowerCase();
|
||||
const filePathParts = normalizedFilePath.split("/");
|
||||
const pathParts = normalizedPath.split("/");
|
||||
|
||||
// Check if the file path contains all parts of the input path in order
|
||||
let filePathIndex = 0;
|
||||
for (const pathPart of pathParts) {
|
||||
while (filePathIndex < filePathParts.length) {
|
||||
if (filePathParts[filePathIndex] === pathPart) {
|
||||
break;
|
||||
}
|
||||
filePathIndex++;
|
||||
}
|
||||
if (filePathIndex >= filePathParts.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -512,7 +527,8 @@ export function extractNoteTitles(query: string): string[] {
|
|||
}
|
||||
|
||||
/**
|
||||
* Process the variable name to generate a note path if it's enclosed in double brackets, otherwise return the variable name as is.
|
||||
* Process the variable name to generate a note path if it's enclosed in double brackets,
|
||||
* otherwise return the variable name as is.
|
||||
*
|
||||
* @param {string} variableName - The name of the variable to process
|
||||
* @return {string} The processed note path or the variable name itself
|
||||
|
|
|
|||
|
|
@ -100,6 +100,25 @@ describe("getNotesFromPath", () => {
|
|||
expect(files).toEqual([]);
|
||||
});
|
||||
|
||||
it("should return only files from the specified subfolder path", async () => {
|
||||
const vault = new Obsidian.Vault();
|
||||
// Mock the getMarkdownFiles method to return our test structure
|
||||
vault.getMarkdownFiles = jest
|
||||
.fn()
|
||||
.mockReturnValue([
|
||||
{ path: "folder/subfolder 1/eng/1.md" },
|
||||
{ path: "folder/subfolder 2/eng/3.md" },
|
||||
{ path: "folder/subfolder 1/eng/2.md" },
|
||||
{ path: "folder/other/note.md" },
|
||||
]);
|
||||
|
||||
const files = await getNotesFromPath(vault, "folder/subfolder 1/eng");
|
||||
expect(files).toEqual([
|
||||
{ path: "folder/subfolder 1/eng/1.md" },
|
||||
{ path: "folder/subfolder 1/eng/2.md" },
|
||||
]);
|
||||
});
|
||||
|
||||
describe("processVariableNameForNotePath", () => {
|
||||
it("should return the note md filename", () => {
|
||||
const variableName = processVariableNameForNotePath("[[test]]");
|
||||
|
|
|
|||
Loading…
Reference in a new issue