diff --git a/src/frontend/components/editor.rs b/src/frontend/components/editor.rs index 84dc41a..aa4553b 100644 --- a/src/frontend/components/editor.rs +++ b/src/frontend/components/editor.rs @@ -1,5 +1,6 @@ use crate::frontend::markdown::render_markdown; -use leptos::{html::Textarea, prelude::*}; +use leptos::{ev::beforeunload, html::Textarea, prelude::*}; +use leptos_use::{use_event_listener, use_window}; #[component] pub fn EditorView( @@ -10,6 +11,14 @@ pub fn EditorView( let (preview, set_preview) = signal(render_markdown(&content.get_untracked())); let (show_preview, set_show_preview) = signal(false); + // Prevent user from accidentally closing the page while editing. Doesnt prevent navigation + // within Ibis. + // https://github.com/Nutomic/ibis/issues/87 + let _ = use_event_listener(use_window(), beforeunload, |evt| { + evt.stop_propagation(); + evt.prevent_default(); + }); + view! {