//! Text editor: an editable CodeMirror with save, a dirty-state indicator,
//! Ctrl/Cmd+S, and save-time conflict handling (the file changed on disk
//! since it was opened).
//!
//! The editor fills the whole content area; its title, Save button and close
//! action live in the top bar (see `views::file_view`). The editor
//! registers its save callback via `register_save` and reports its
//! dirty/saving state through the shared signals.
use leptos::prelude::*;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_futures::spawn_local;
use crate::api::{self, ApiError};
use crate::cm;
use crate::components::icon::Icon;
use crate::components::modal::Modal;
use crate::components::toast::{ToastMsg, show};
use crate::i18n;
use crate::icons::IconName;
use crate::views::dialogs::ConfirmDialog;
use crate::views::file_view::FileView;
/// Read the current document and PUT it, updating the editor's state.
///
/// `force` skips the server's conflict check (used by the "Overwrite" button).
#[allow(clippy::too_many_arguments)] // long signal/JS-handle list
async fn do_save(
target: FileView,
force: bool,
cm_view: StoredValue