From ec837fa6d78e622cbc1b3421dfaf9def772b9ecf Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 6 Apr 2022 17:12:36 -0700 Subject: [PATCH] Update breadcrumbs when multibuffers' excerpts change --- crates/diagnostics/src/diagnostics.rs | 2 +- crates/editor/src/multi_buffer.rs | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 1d317278a6..55a41a4468 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -16,6 +16,7 @@ use language::{ Bias, Buffer, Diagnostic, DiagnosticEntry, DiagnosticSeverity, Point, Selection, SelectionGoal, }; use project::{DiagnosticSummary, Project, ProjectPath}; +use settings::Settings; use std::{ any::{Any, TypeId}, cmp::Ordering, @@ -26,7 +27,6 @@ use std::{ }; use util::TryFutureExt; use workspace::{ItemHandle as _, ItemNavHistory, Workspace}; -use settings::Settings; action!(Deploy); diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index cf88473435..ae061196bd 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -788,7 +788,7 @@ impl MultiBuffer { old: edit_start..edit_start, new: edit_start..edit_end, }]); - + cx.emit(Event::Edited); cx.notify(); ids } @@ -802,10 +802,12 @@ impl MultiBuffer { snapshot.trailing_excerpt_update_count += 1; snapshot.is_dirty = false; snapshot.has_conflict = false; + self.subscriptions.publish_mut([Edit { old: 0..prev_len, new: 0..0, }]); + cx.emit(Event::Edited); cx.notify(); } @@ -993,6 +995,7 @@ impl MultiBuffer { } self.subscriptions.publish_mut(edits); + cx.emit(Event::Edited); cx.notify(); } @@ -2928,7 +2931,7 @@ mod tests { use gpui::MutableAppContext; use language::{Buffer, Rope}; use rand::prelude::*; - use std::env; + use std::{env, rc::Rc}; use text::{Point, RandomCharIter}; use util::test::sample_text; @@ -2985,6 +2988,15 @@ mod tests { let buffer_2 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'g'), cx)); let multibuffer = cx.add_model(|_| MultiBuffer::new(0)); + let events = Rc::new(RefCell::new(Vec::::new())); + multibuffer.update(cx, |_, cx| { + let events = events.clone(); + cx.subscribe(&multibuffer, move |_, _, event, _| { + events.borrow_mut().push(event.clone()) + }) + .detach(); + }); + let subscription = multibuffer.update(cx, |multibuffer, cx| { let subscription = multibuffer.subscribe(); multibuffer.push_excerpts(buffer_1.clone(), [Point::new(1, 2)..Point::new(2, 5)], cx); @@ -3009,6 +3021,12 @@ mod tests { subscription }); + // Adding excerpts emits an edited event. + assert_eq!( + events.borrow().as_slice(), + &[Event::Edited, Event::Edited, Event::Edited] + ); + let snapshot = multibuffer.read(cx).snapshot(cx); assert_eq!( snapshot.text(),