From 3f486ca5c2549ab861c970ce606011a06bc893c4 Mon Sep 17 00:00:00 2001 From: Luis Alberto Jaramillo Gonzalez Date: Wed, 3 Dec 2025 09:25:24 -0500 Subject: [PATCH] Add validation if users hit Restore plain text to document in reading mode --- src/DecryptModal.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DecryptModal.ts b/src/DecryptModal.ts index 3a2bb6d..1ee34f5 100644 --- a/src/DecryptModal.ts +++ b/src/DecryptModal.ts @@ -1,4 +1,4 @@ -import { App, Editor, EditorPosition, Modal, Notice, Setting } from "obsidian"; +import { App, Editor, EditorPosition, MarkdownView, Modal, Notice, Setting } from "obsidian"; import GpgEncryptPlugin from "main"; // Decrypt modal (Works for inline and document encryption) @@ -41,6 +41,13 @@ export class DecryptModal extends Modal { if (this.app.workspace.activeEditor && this.app.workspace.activeEditor.editor) { // Button restore to document buttons.addButton((btn) => btn.setButtonText("Restore plain text to document").setCta().onClick(async() => { + // Check if the view is in reading mode + const activeView = this.app.workspace.getActiveViewOfType(MarkdownView); + if (activeView && activeView.getMode() === "preview") { + // Error message for reading mode + new Notice("Cannot restore plain text in reading mode. Please switch to Live Preview mode to restore the text."); + return; + } // Check if activeEditor or editor are available if (this.app.workspace.activeEditor && this.app.workspace.activeEditor.editor) { // The function to replace the encrypted with plaintext is executed