Pass a handle to the current view model when spawning

Most of the time, we'll want a way to get a reference back to the current view or model, so this facilitates that common case.
This commit is contained in:
Nathan Sobo
2021-05-12 15:28:59 -06:00
parent fa6bd1f926
commit a3be5595dd
6 changed files with 41 additions and 44 deletions
+1 -2
View File
@@ -477,9 +477,8 @@ impl Buffer {
let snapshot = self.snapshot();
let version = self.version.clone();
let file = self.file.clone();
let handle = ctx.handle();
ctx.spawn(|mut ctx| async move {
ctx.spawn(|handle, mut ctx| async move {
if let Some(file) = new_file.as_ref().or(file.as_ref()) {
let result = ctx.read(|ctx| file.save(snapshot, ctx.as_ref())).await;
if result.is_ok() {
+4 -6
View File
@@ -2347,10 +2347,9 @@ impl BufferView {
ctx.notify();
let epoch = self.next_blink_epoch();
let handle = ctx.handle();
ctx.spawn(|mut ctx| async move {
ctx.spawn(|this, mut ctx| async move {
Timer::after(CURSOR_BLINK_INTERVAL).await;
handle.update(&mut ctx, |this, ctx| {
this.update(&mut ctx, |this, ctx| {
this.resume_cursor_blinking(epoch, ctx);
})
})
@@ -2370,10 +2369,9 @@ impl BufferView {
ctx.notify();
let epoch = self.next_blink_epoch();
let handle = ctx.handle();
ctx.spawn(|mut ctx| async move {
ctx.spawn(|this, mut ctx| async move {
Timer::after(CURSOR_BLINK_INTERVAL).await;
handle.update(&mut ctx, |this, ctx| this.blink_cursors(epoch, ctx));
this.update(&mut ctx, |this, ctx| this.blink_cursors(epoch, ctx));
})
.detach();
}