@@ -35,13 +35,13 @@ pub struct Document {
3535 // /// Corresponding language scope name. Usually `source.<lang>`.
3636 pub(crate) language: Option<Arc<LanguageConfiguration>>,
3737
38− modified: bool,
3938 /// Pending changes since last history commit.
4039 changes: ChangeSet,
4140 /// State at last commit. Used for calculating reverts.
4241 old_state: Option<State>,
4342 /// Undo tree.
4443 history: History,
44+ last_saved_revision: usize,
4545 version: i32, // should be usize?
4646
4747 pub diagnostics: Vec<Diagnostic>,
@@ -81,12 +81,12 @@ impl Document {
8181 restore_cursor: false,
8282 syntax: None,
8383 language: None,
84− modified: false,
8584 changes,
8685 old_state,
8786 diagnostics: Vec::new(),
8887 version: 0,
8988 history: History::default(),
89+ last_saved_revision: 0,
9090 language_server: None,
9191 }
9292 }
@@ -131,7 +131,7 @@ impl Document {
131131 let language_server = self.language_server.clone();
132132
133133 // reset the modified flag
134− self.modified = false;
134+ self.last_saved_revision = self.history.current_revision();
135135
136136 async move {
137137 use smol::{fs::File, prelude::*};
@@ -246,10 +246,6 @@ impl Document {
246246
247247 let success = self._apply(transaction, view_id);
248248
249− self.modified = true;
250− // TODO: be smarter about modified by keeping track of saved version instead. That way if
251− // current version == version then it's not modified.
252−
253249 if !transaction.changes().is_empty() {
254250 // Compose this transaction with the previous one
255251 take_with(&mut self.changes, |changes| {
@@ -307,8 +303,10 @@ impl Document {
307303 }
308304
309305 #[inline]
310− pub fn modified(&self) -> bool {
311− self.modified
306+ pub fn is_modified(&self) -> bool {
307+ self.path.is_some()
308+ && (self.history.current_revision() != self.last_saved_revision
309+ || !self.changes.is_empty())
312310 }
313311
314312 #[inline]