On rename, replace background highlights with transparent text highlights
This commit is contained in:
parent
951fd1ab36
commit
c35a96c425
2 changed files with 30 additions and 9 deletions
|
@ -174,8 +174,11 @@ impl DisplayMap {
|
||||||
.insert(Some(type_id), Arc::new((style, ranges)));
|
.insert(Some(type_id), Arc::new((style, ranges)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_text_highlights(&mut self, type_id: TypeId) {
|
pub fn clear_text_highlights(
|
||||||
self.text_highlights.remove(&Some(type_id));
|
&mut self,
|
||||||
|
type_id: TypeId,
|
||||||
|
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||||
|
self.text_highlights.remove(&Some(type_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) {
|
pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) {
|
||||||
|
|
|
@ -134,6 +134,9 @@ action!(ConfirmCompletion, Option<usize>);
|
||||||
action!(ConfirmCodeAction, Option<usize>);
|
action!(ConfirmCodeAction, Option<usize>);
|
||||||
action!(OpenExcerpts);
|
action!(OpenExcerpts);
|
||||||
|
|
||||||
|
enum DocumentHighlightRead {}
|
||||||
|
enum DocumentHighlightWrite {}
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpener>>) {
|
pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpener>>) {
|
||||||
path_openers.push(Box::new(items::BufferOpener));
|
path_openers.push(Box::new(items::BufferOpener));
|
||||||
cx.add_bindings(vec![
|
cx.add_bindings(vec![
|
||||||
|
@ -2421,13 +2424,14 @@ impl Editor {
|
||||||
project.document_highlights(&cursor_buffer, cursor_buffer_position, cx)
|
project.document_highlights(&cursor_buffer, cursor_buffer_position, cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
enum DocumentHighlightRead {}
|
|
||||||
enum DocumentHighlightWrite {}
|
|
||||||
|
|
||||||
self.document_highlights_task = Some(cx.spawn_weak(|this, mut cx| async move {
|
self.document_highlights_task = Some(cx.spawn_weak(|this, mut cx| async move {
|
||||||
let highlights = highlights.log_err().await;
|
let highlights = highlights.log_err().await;
|
||||||
if let Some((this, highlights)) = this.upgrade(&cx).zip(highlights) {
|
if let Some((this, highlights)) = this.upgrade(&cx).zip(highlights) {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
|
if this.pending_rename.is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let buffer_id = cursor_position.buffer_id;
|
let buffer_id = cursor_position.buffer_id;
|
||||||
let excerpt_id = cursor_position.excerpt_id.clone();
|
let excerpt_id = cursor_position.excerpt_id.clone();
|
||||||
let style = this.style(cx);
|
let style = this.style(cx);
|
||||||
|
@ -4436,8 +4440,19 @@ impl Editor {
|
||||||
editor.select_all(&SelectAll, cx);
|
editor.select_all(&SelectAll, cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let ranges = this
|
||||||
|
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|(_, ranges)| ranges)
|
||||||
|
.chain(
|
||||||
|
this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|(_, ranges)| ranges),
|
||||||
|
)
|
||||||
|
.collect();
|
||||||
this.highlight_text::<Rename>(
|
this.highlight_text::<Rename>(
|
||||||
vec![range.clone()],
|
ranges,
|
||||||
HighlightStyle {
|
HighlightStyle {
|
||||||
fade_out: Some(style.rename_fade),
|
fade_out: Some(style.rename_fade),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -5392,10 +5407,13 @@ impl Editor {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_text_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn clear_text_highlights<T: 'static>(
|
||||||
self.display_map
|
&mut self,
|
||||||
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
self.display_map
|
||||||
|
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_blink_epoch(&mut self) -> usize {
|
fn next_blink_epoch(&mut self) -> usize {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue