Properly place the caret into the window of the file opened
co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
54c1e77aff
commit
0db7f4202a
1 changed files with 39 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
||||||
use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor};
|
use editor::{scroll::autoscroll::Autoscroll, Bias, DisplayPoint, Editor};
|
||||||
use fuzzy::PathMatch;
|
use fuzzy::PathMatch;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::*, AppContext, ModelHandle, MouseState, Task, ViewContext, WeakViewHandle,
|
actions, elements::*, AppContext, ModelHandle, MouseState, Task, ViewContext, WeakViewHandle,
|
||||||
|
@ -308,41 +308,54 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
path: m.path.clone(),
|
path: m.path.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
let open_task = workspace.update(cx, |workspace, cx| {
|
||||||
workspace
|
workspace.open_path(project_path.clone(), None, true, cx)
|
||||||
.open_path(project_path.clone(), None, true, cx)
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
let workspace = workspace.downgrade();
|
||||||
if let Some(query) = &self.latest_search_query {
|
|
||||||
let row = query.file_row;
|
cx.spawn(|file_finder, mut cx| async move {
|
||||||
let column = query.file_column;
|
let item = open_task.await.log_err()?;
|
||||||
if let Some(row) = row {
|
|
||||||
if let Some(active_editor) = workspace
|
let (row, col) = file_finder
|
||||||
.active_item(cx)
|
.read_with(&cx, |file_finder, _| {
|
||||||
.and_then(|active_item| active_item.downcast::<Editor>())
|
file_finder
|
||||||
{
|
.delegate()
|
||||||
// TODO kb does not open proper lines for the first time
|
.latest_search_query
|
||||||
active_editor.update(cx, |active_editor, cx| {
|
.as_ref()
|
||||||
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
.map(|query| (query.file_row, query.file_column))
|
||||||
|
})
|
||||||
|
.log_err()
|
||||||
|
.flatten()?;
|
||||||
|
|
||||||
|
if let Some(row) = row {
|
||||||
|
if let Some(active_editor) = item.downcast::<Editor>() {
|
||||||
|
active_editor
|
||||||
|
.downgrade()
|
||||||
|
.update(&mut cx, |editor, cx| {
|
||||||
|
let snapshot = editor.snapshot(cx).display_snapshot;
|
||||||
let point = DisplayPoint::new(
|
let point = DisplayPoint::new(
|
||||||
row.saturating_sub(1),
|
row.saturating_sub(1),
|
||||||
column.map(|column| column.saturating_sub(1)).unwrap_or(0),
|
col.map(|column| column.saturating_sub(1)).unwrap_or(0),
|
||||||
)
|
)
|
||||||
.to_point(&snapshot);
|
.to_point(&snapshot);
|
||||||
active_editor.change_selections(
|
let point =
|
||||||
Some(Autoscroll::center()),
|
snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
||||||
cx,
|
editor.change_selections(Some(Autoscroll::center()), cx, |s| {
|
||||||
|s| s.select_ranges([point..point]),
|
s.select_ranges([point..point])
|
||||||
);
|
});
|
||||||
})
|
})
|
||||||
}
|
.log_err();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace.dismiss_modal(cx);
|
workspace
|
||||||
});
|
.update(&mut cx, |workspace, cx| workspace.dismiss_modal(cx))
|
||||||
|
.log_err();
|
||||||
|
|
||||||
|
Some(())
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue