//! Text editor (milestone 5): 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).
use leptos::prelude::*;
use wasm_bindgen::JsValue;
use wasm_bindgen::closure::Closure;
use wasm_bindgen_futures::spawn_local;
use web_sys::MouseEvent;
use crate::api::{self, ApiError};
use crate::cm;
use crate::components::icon::Icon;
use crate::components::toast::{ToastMsg, show};
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