Don't select entire item when jumping to a project symbol

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-02-22 12:56:43 -08:00
parent 5d2201c4ca
commit 6be4b1ef6a

View file

@ -337,7 +337,11 @@ impl ProjectSymbolsView {
)) ))
.boxed(), .boxed(),
) )
.with_child(Label::new(path.to_string(), style.label.clone()).boxed()) .with_child(
// Avoid styling the path differently when it is selected, since
// the symbol's syntax highlighting doesn't change when selected.
Label::new(path.to_string(), settings.theme.selector.item.label.clone()).boxed(),
)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.boxed() .boxed()
@ -372,18 +376,19 @@ impl ProjectSymbolsView {
cx.spawn(|workspace, mut cx| async move { cx.spawn(|workspace, mut cx| async move {
let buffer = buffer.await?; let buffer = buffer.await?;
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
let start; let position = buffer
let end; .read(cx)
{ .clip_point_utf16(symbol.range.start, Bias::Left);
let buffer = buffer.read(cx); let editor = workspace
start = buffer.clip_point_utf16(symbol.range.start, Bias::Left); .open_item(BufferItemHandle(buffer), cx)
end = buffer.clip_point_utf16(symbol.range.end, Bias::Left); .downcast::<Editor>()
} .unwrap();
let editor = workspace.open_item(BufferItemHandle(buffer), cx);
let editor = editor.downcast::<Editor>().unwrap();
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.select_ranges([start..end], Some(Autoscroll::Center), cx); editor.select_ranges(
[position..position],
Some(Autoscroll::Center),
cx,
);
}); });
}); });
Ok::<_, anyhow::Error>(()) Ok::<_, anyhow::Error>(())