Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/modules/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ export default class NoteResolver {
path: dir === "/" ? basename + ".md" : join(dir, basename + ".md"),
};
};
getFolderNotePathAfterMove: API["getFolderNotePathAfterMove"] = (folderAfterMove, folderBeforeMovePath, strategy) => {
if (!folderBeforeMovePath) {
return null;
}

if (strategy === undefined) strategy = this.settings.folderNotePref;

switch (strategy) {
case NoteLoc.Index:
return this.findFolderNote(this.getFolderNotePath(folderAfterMove.path, strategy));
case NoteLoc.Inside:
const notePath = join(folderAfterMove.path, getBase(folderBeforeMovePath) + ".md")
const note = this.vault.getAbstractFileByPath(notePath);
if (note && note instanceof TFile) return note;
else return null;
case NoteLoc.Outside:
return this.findFolderNote(this.getFolderNotePath(folderBeforeMovePath, strategy));
default:
assertNever(strategy);
}
};

// Note Operations

Expand Down
10 changes: 7 additions & 3 deletions src/modules/vault-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class VaultHandler {

registerEvent = () => {
this.plugin.registerEvent(this.on("create", this.onChange));
this.plugin.registerEvent(this.on("rename", this.onChange));
this.plugin.registerEvent(this.on("rename", this.onRename));
this.plugin.registerEvent(this.on("delete", this.onDelete));
};

Expand All @@ -55,16 +55,20 @@ export default class VaultHandler {
return renameOnly || syncLoc;
}

onRename = (af: TAbstractFile, oldPath: string) => {
setTimeout(() => this.onChange(af, oldPath), 500);
}

onChange = (af: TAbstractFile, oldPath?: string) => {
const { getFolderNote, getFolderFromNote, getFolderNotePath } = this.finder;
const { getFolderNote, getFolderFromNote, getFolderNotePath, getFolderNotePathAfterMove } = this.finder;

function getOldLinked(af: TFile): TFolder | null;
function getOldLinked(af: TFolder): TFile | null;
function getOldLinked(af: TAbstractFile): TFile | TFolder | null;
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function getOldLinked(af: TAbstractFile): TFile | TFolder | null {
if (af instanceof TFolder) {
return oldPath ? getFolderNote(oldPath) : null;
return getFolderNotePathAfterMove(af, oldPath);
} else if (af instanceof TFile) {
return oldPath && isMd(oldPath) ? getFolderFromNote(oldPath) : null;
} else return null;
Expand Down
5 changes: 5 additions & 0 deletions src/typings/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default interface FolderNoteAPI {
/** Generate folder note content for given folder based on template */
getNewFolderNote(folder: TFolder): string;

getFolderNotePathAfterMove(folderAfterMove: TFolder, folderBeforeMovePath?: string, strategy?: NoteLoc): TFile | null;

OpenFolderNote(
folder: TFolder | string,
dryrun?: boolean,
Expand Down Expand Up @@ -154,6 +156,9 @@ export const getApi = (plugin: FNCore): FolderNoteAPI => {
get getFolderNotePath() {
return plugin.resolver.getFolderNotePath;
},
get getFolderNotePathAfterMove() {
return plugin.resolver.getFolderNotePathAfterMove;
},
get DeleteLinkedFolder() {
return plugin.resolver.DeleteLinkedFolder;
},
Expand Down