fix: Reset edit mode when navigating to another locked note

Signed-off-by: Felvesthe <23108389+Felvesthe@users.noreply.github.com>
This commit is contained in:
Felvesthe 2025-12-05 13:10:01 +01:00
parent 1bbbb63f90
commit 4a2fbbbb9d

View file

@ -114,7 +114,7 @@ export default class NoteLockerPlugin extends Plugin {
this.registerEvent( this.registerEvent(
this.app.workspace.on("active-leaf-change", (leaf) => { this.app.workspace.on("active-leaf-change", (leaf) => {
this.updateLeafMode(leaf); this.updateLeafMode(leaf, true);
this.statusBarUI.updateStatusBarButton(); this.statusBarUI.updateStatusBarButton();
}) })
); );
@ -148,6 +148,7 @@ export default class NoteLockerPlugin extends Plugin {
this.app.workspace.on("file-open", () => { this.app.workspace.on("file-open", () => {
this.statusBarUI.updateStatusBarButton(); this.statusBarUI.updateStatusBarButton();
this.fileExplorerUI.updateFileExplorerIcons(); this.fileExplorerUI.updateFileExplorerIcons();
this.updateLeafMode(this.app.workspace.getLeaf(false), true);
}) })
); );
@ -162,7 +163,7 @@ export default class NoteLockerPlugin extends Plugin {
private initializeExistingLeaves() { private initializeExistingLeaves() {
this.app.workspace this.app.workspace
.getLeavesOfType("markdown") .getLeavesOfType("markdown")
.forEach((leaf) => this.updateLeafMode(leaf)); .forEach((leaf) => this.updateLeafMode(leaf, true));
} }
private addBulkLockMenuItem(menu: Menu, files: TAbstractFile[]) { private addBulkLockMenuItem(menu: Menu, files: TAbstractFile[]) {
@ -471,7 +472,7 @@ export default class NoteLockerPlugin extends Plugin {
return false; return false;
} }
public updateLeafMode(leaf: WorkspaceLeaf | null) { public updateLeafMode(leaf: WorkspaceLeaf | null, fromNavigation: boolean = false) {
if (!leaf || !(leaf.view instanceof MarkdownView)) return; if (!leaf || !(leaf.view instanceof MarkdownView)) return;
const { view } = leaf; const { view } = leaf;
@ -488,17 +489,11 @@ export default class NoteLockerPlugin extends Plugin {
...state, ...state,
state: { ...state.state, mode: 'preview' }, state: { ...state.state, mode: 'preview' },
}); });
if (this.app.workspace.activeLeaf === leaf) {
new StrictUnlockModal(this.app, () => {
this.toggleStrictLock(path);
}).open();
}
return; return;
} }
} else if (isLocked) { } else if (isLocked) {
const state = leaf.getViewState(); const state = leaf.getViewState();
if (this.settings.preventEditInLockedNotes && state.state?.mode === 'source') { if ((fromNavigation || this.settings.preventEditInLockedNotes) && state.state?.mode === 'source') {
leaf.setViewState({ leaf.setViewState({
...state, ...state,
state: { ...state.state, mode: 'preview' }, state: { ...state.state, mode: 'preview' },
@ -554,7 +549,6 @@ export default class NoteLockerPlugin extends Plugin {
if (!lockBtn) { if (!lockBtn) {
lockBtn = document.createElement('div'); lockBtn = document.createElement('div');
lockBtn.addClass('view-action', 'clickable-icon', 'note-locker-strict-btn'); lockBtn.addClass('view-action', 'clickable-icon', 'note-locker-strict-btn');
lockBtn.addClass('view-action', 'clickable-icon', 'note-locker-strict-btn');
lockBtn.setAttribute('aria-label', 'Strictly locked'); lockBtn.setAttribute('aria-label', 'Strictly locked');
setIcon(lockBtn, 'lock-keyhole'); setIcon(lockBtn, 'lock-keyhole');
@ -577,7 +571,6 @@ export default class NoteLockerPlugin extends Plugin {
if (lockBtn) lockBtn.remove(); if (lockBtn) lockBtn.remove();
} }
async loadSettings() { async loadSettings() {
const loaded = await this.loadData(); const loaded = await this.loadData();
if (loaded) { if (loaded) {