Highlight text when the diff is the same
This commit is contained in:
parent
a93583065b
commit
a2671a29a0
1 changed files with 21 additions and 2 deletions
|
@ -86,6 +86,8 @@ impl RefactoringAssistant {
|
||||||
|
|
||||||
while let Some(hunks) = hunks_rx.next().await {
|
while let Some(hunks) = hunks_rx.next().await {
|
||||||
editor.update(&mut cx, |editor, cx| {
|
editor.update(&mut cx, |editor, cx| {
|
||||||
|
let mut highlights = Vec::new();
|
||||||
|
|
||||||
editor.buffer().update(cx, |buffer, cx| {
|
editor.buffer().update(cx, |buffer, cx| {
|
||||||
buffer.start_transaction(cx);
|
buffer.start_transaction(cx);
|
||||||
for hunk in hunks {
|
for hunk in hunks {
|
||||||
|
@ -102,16 +104,33 @@ impl RefactoringAssistant {
|
||||||
edit_start = edit_end;
|
edit_start = edit_end;
|
||||||
}
|
}
|
||||||
crate::diff::Hunk::Keep { len } => {
|
crate::diff::Hunk::Keep { len } => {
|
||||||
|
let edit_end = edit_start + len;
|
||||||
|
let edit_range = snapshot.anchor_after(edit_start)
|
||||||
|
..snapshot.anchor_before(edit_end);
|
||||||
|
highlights.push(edit_range);
|
||||||
edit_start += len;
|
edit_start += len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.end_transaction(cx);
|
buffer.end_transaction(cx);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
editor.highlight_text::<Self>(
|
||||||
|
highlights,
|
||||||
|
gpui::fonts::HighlightStyle {
|
||||||
|
fade_out: Some(0.6),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
diff.await?;
|
diff.await?;
|
||||||
|
editor.update(&mut cx, |editor, cx| {
|
||||||
|
editor.clear_text_highlights::<Self>(cx);
|
||||||
|
})?;
|
||||||
|
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
}
|
}
|
||||||
.log_err()
|
.log_err()
|
||||||
|
@ -172,7 +191,7 @@ impl RefactoringModal {
|
||||||
Some(Arc::new(|theme| theme.search.editor.input.clone())),
|
Some(Arc::new(|theme| theme.search.editor.input.clone())),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
editor.set_text("Replace with match statement.", cx);
|
editor.set_text("Replace with if statement.", cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
cx.add_view(|_| RefactoringModal {
|
cx.add_view(|_| RefactoringModal {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue