|
|
@ -657,6 +657,7 @@ pub struct Editor {
|
|
|
|
// https://stackoverflow.com/a/66875668
|
|
|
|
// https://stackoverflow.com/a/66875668
|
|
|
|
pub saves: HashMap<DocumentId, UnboundedSender<Once<DocumentSavedEventFuture>>>,
|
|
|
|
pub saves: HashMap<DocumentId, UnboundedSender<Once<DocumentSavedEventFuture>>>,
|
|
|
|
pub save_queue: SelectAll<Flatten<UnboundedReceiverStream<Once<DocumentSavedEventFuture>>>>,
|
|
|
|
pub save_queue: SelectAll<Flatten<UnboundedReceiverStream<Once<DocumentSavedEventFuture>>>>,
|
|
|
|
|
|
|
|
pub write_count: usize,
|
|
|
|
|
|
|
|
|
|
|
|
pub count: Option<std::num::NonZeroUsize>,
|
|
|
|
pub count: Option<std::num::NonZeroUsize>,
|
|
|
|
pub selected_register: Option<char>,
|
|
|
|
pub selected_register: Option<char>,
|
|
|
@ -761,6 +762,7 @@ impl Editor {
|
|
|
|
documents: BTreeMap::new(),
|
|
|
|
documents: BTreeMap::new(),
|
|
|
|
saves: HashMap::new(),
|
|
|
|
saves: HashMap::new(),
|
|
|
|
save_queue: SelectAll::new(),
|
|
|
|
save_queue: SelectAll::new(),
|
|
|
|
|
|
|
|
write_count: 0,
|
|
|
|
count: None,
|
|
|
|
count: None,
|
|
|
|
selected_register: None,
|
|
|
|
selected_register: None,
|
|
|
|
macro_recording: None,
|
|
|
|
macro_recording: None,
|
|
|
@ -1206,6 +1208,8 @@ impl Editor {
|
|
|
|
.send(stream::once(Box::pin(future)))
|
|
|
|
.send(stream::once(Box::pin(future)))
|
|
|
|
.map_err(|err| anyhow!("failed to send save event: {}", err))?;
|
|
|
|
.map_err(|err| anyhow!("failed to send save event: {}", err))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.write_count += 1;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1332,6 +1336,7 @@ impl Editor {
|
|
|
|
biased;
|
|
|
|
biased;
|
|
|
|
|
|
|
|
|
|
|
|
Some(event) = self.save_queue.next() => {
|
|
|
|
Some(event) = self.save_queue.next() => {
|
|
|
|
|
|
|
|
self.write_count -= 1;
|
|
|
|
EditorEvent::DocumentSaved(event)
|
|
|
|
EditorEvent::DocumentSaved(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(config_event) = self.config_events.1.recv() => {
|
|
|
|
Some(config_event) = self.config_events.1.recv() => {
|
|
|
@ -1350,17 +1355,21 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn flush_writes(&mut self) {
|
|
|
|
pub async fn flush_writes(&mut self) {
|
|
|
|
while let Some(save_event) = self.save_queue.next().await {
|
|
|
|
while self.write_count > 0 {
|
|
|
|
match &save_event {
|
|
|
|
if let Some(save_event) = self.save_queue.next().await {
|
|
|
|
Ok(event) => {
|
|
|
|
match &save_event {
|
|
|
|
let doc = doc_mut!(self, &event.doc_id);
|
|
|
|
Ok(event) => {
|
|
|
|
doc.set_last_saved_revision(event.revision);
|
|
|
|
let doc = doc_mut!(self, &event.doc_id);
|
|
|
|
}
|
|
|
|
doc.set_last_saved_revision(event.revision);
|
|
|
|
Err(err) => {
|
|
|
|
}
|
|
|
|
log::error!("error saving document: {}", err);
|
|
|
|
Err(err) => {
|
|
|
|
}
|
|
|
|
log::error!("error saving document: {}", err);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// TODO: if is_err: break?
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: if is_err: break?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.write_count -= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|