mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Fix #58
This commit is contained in:
parent
270a19e462
commit
fa380c0544
4 changed files with 50 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "folder-notes",
|
||||
"name": "Folder notes",
|
||||
"version": "1.6.8",
|
||||
"version": "1.6.9",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.",
|
||||
"author": "Lost Paul",
|
||||
|
|
|
|||
27
src/main.ts
27
src/main.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice } from 'obsidian';
|
||||
import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice, Platform } from 'obsidian';
|
||||
import { DEFAULT_SETTINGS, FolderNotesSettings, SettingsTab } from './settings/SettingsTab';
|
||||
import { Commands } from './Commands';
|
||||
import { FileExplorerWorkspaceLeaf } from './globals';
|
||||
|
|
@ -45,6 +45,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
(<Element>rec.target).querySelectorAll('div.nav-folder-title-content')
|
||||
.forEach((element: HTMLElement) => {
|
||||
if (element.onclick) return;
|
||||
if (Platform.isMobile && this.settings.disableOpenFolderNoteOnClick) return;
|
||||
element.onclick = (event: MouseEvent) => handleFolderClick(event, this);
|
||||
});
|
||||
if (!this.settings.openFolderNoteOnClickInPath) { return; }
|
||||
|
|
@ -87,18 +88,17 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
|
||||
this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||||
this.loadFileClasses();
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => {
|
||||
if (!(file instanceof TFile)) { return; }
|
||||
// parent is null here even if the parent exists
|
||||
// not entirely sure why
|
||||
const parentPath = this.getFolderPathFromString(file.path);
|
||||
const parentName = this.getFileNameFromPathString(parentPath);
|
||||
if (parentName !== file.basename) { return; }
|
||||
this.removeCSSClassFromEL(parentPath, 'has-folder-note');
|
||||
const parentFolder = getFolder(this, file);
|
||||
this.removeCSSClassFromEL(parentFolder?.path, 'has-folder-note');
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
|
||||
if (file instanceof TFile) {
|
||||
const folderName = extractFolderName(this.settings.folderNoteName, file.basename);
|
||||
|
|
@ -145,6 +145,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
return handleFileRename(file, oldPath, this);
|
||||
}
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => {
|
||||
if (file instanceof TFile) {
|
||||
const folder = getFolder(this, file);
|
||||
|
|
@ -189,6 +190,18 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
try {
|
||||
const folderOverview = new FolderOverview(this, ctx, source, el);
|
||||
folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
|
||||
// this.app.vault.on('delete', () => {
|
||||
// folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
// });
|
||||
|
||||
// this.app.vault.on('rename', () => {
|
||||
// folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
// });
|
||||
|
||||
// this.app.vault.on('create', () => {
|
||||
// folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
// });
|
||||
} catch (e) {
|
||||
new Notice('Error creating folder overview (folder notes plugin) - check console for more details');
|
||||
console.error(e);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,21 @@ export async function renderFileExplorer(settingsTab: SettingsTab) {
|
|||
})
|
||||
);
|
||||
|
||||
const setting2 = new Setting(containerEl)
|
||||
.setName('Don\'t open folder notes by clicking on the name (on mobile)')
|
||||
.setDesc('Folder notes don\'t open when clicking on the name of the folder (on mobile)')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.disableOpenFolderNoteOnClick)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.disableOpenFolderNoteOnClick = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
setting2.infoEl.appendText('Requires a restart to take effect');
|
||||
setting2.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Only open folder notes through the name')
|
||||
.setDesc('Only open folder notes in the file explorer by clicking on the folder name')
|
||||
|
|
@ -122,17 +137,17 @@ export async function renderFileExplorer(settingsTab: SettingsTab) {
|
|||
.setName('Cursive the name of folder notes')
|
||||
.setDesc('Make the folder name cursive in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.cursiveName)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.cursiveName = value;
|
||||
if (value) {
|
||||
document.body.classList.add('folder-note-cursive');
|
||||
} else {
|
||||
document.body.classList.remove('folder-note-cursive');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.cursiveName)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.cursiveName = value;
|
||||
if (value) {
|
||||
document.body.classList.add('folder-note-cursive');
|
||||
} else {
|
||||
document.body.classList.remove('folder-note-cursive');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export interface FolderNotesSettings {
|
|||
boldNameInPath: boolean;
|
||||
cursiveName: boolean;
|
||||
cursiveNameInPath: boolean;
|
||||
disableOpenFolderNoteOnClick: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
||||
|
|
@ -98,6 +99,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
boldNameInPath: false,
|
||||
cursiveName: false,
|
||||
cursiveNameInPath: false,
|
||||
disableOpenFolderNoteOnClick: false,
|
||||
};
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
|
|
|
|||
Loading…
Reference in a new issue