Add validation if users hit Restore plain text to document in reading mode

This commit is contained in:
Luis Alberto Jaramillo Gonzalez 2025-12-03 09:25:24 -05:00
parent a2ab8a96b0
commit 3f486ca5c2
No known key found for this signature in database
GPG key ID: 0444CB0073EDFBB5

View file

@ -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