//! 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::JsValue;
use wasm_bindgen::closure::Closure;
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;
/// A text file the user wants to edit.
#[derive(Clone)]
pub struct EditTarget {
pub root_id: i64,
/// Path relative to the root (e.g. "docs/a.txt").
pub path: String,
/// Display name (used for the title + language detection).
pub name: String,
/// True in read-only folders: the file is shown, not editable.
pub readonly: bool,
}
/// 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: EditTarget,
force: bool,
cm_view: StoredValue