mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 09:13:21 +03:00
tasks: Fix divider position in modal (#11049)
The divider between templates and recent runs is constant, regardless of the currently used filter string; this can lead to situations where an user can remove the predefined task, which isn't good at all. Additionally, in this PR I've made it so that recent runs always show up before task templates in filtered list. Release Notes: - Fixed position of list divider in task modal.
This commit is contained in:
parent
eb7bd0b98a
commit
bacc92333a
@ -62,6 +62,7 @@ pub(crate) struct TasksModalDelegate {
|
|||||||
inventory: Model<Inventory>,
|
inventory: Model<Inventory>,
|
||||||
candidates: Option<Vec<(TaskSourceKind, ResolvedTask)>>,
|
candidates: Option<Vec<(TaskSourceKind, ResolvedTask)>>,
|
||||||
last_used_candidate_index: Option<usize>,
|
last_used_candidate_index: Option<usize>,
|
||||||
|
divider_index: Option<usize>,
|
||||||
matches: Vec<StringMatch>,
|
matches: Vec<StringMatch>,
|
||||||
selected_index: usize,
|
selected_index: usize,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
@ -82,6 +83,7 @@ impl TasksModalDelegate {
|
|||||||
candidates: None,
|
candidates: None,
|
||||||
matches: Vec::new(),
|
matches: Vec::new(),
|
||||||
last_used_candidate_index: None,
|
last_used_candidate_index: None,
|
||||||
|
divider_index: None,
|
||||||
selected_index: 0,
|
selected_index: 0,
|
||||||
prompt: String::default(),
|
prompt: String::default(),
|
||||||
task_context,
|
task_context,
|
||||||
@ -255,7 +257,17 @@ impl PickerDelegate for TasksModalDelegate {
|
|||||||
.update(&mut cx, |picker, _| {
|
.update(&mut cx, |picker, _| {
|
||||||
let delegate = &mut picker.delegate;
|
let delegate = &mut picker.delegate;
|
||||||
delegate.matches = matches;
|
delegate.matches = matches;
|
||||||
|
if let Some(index) = delegate.last_used_candidate_index {
|
||||||
|
delegate.matches.sort_by_key(|m| m.candidate_id > index);
|
||||||
|
}
|
||||||
|
|
||||||
delegate.prompt = query;
|
delegate.prompt = query;
|
||||||
|
delegate.divider_index = delegate.last_used_candidate_index.and_then(|index| {
|
||||||
|
let index = delegate
|
||||||
|
.matches
|
||||||
|
.partition_point(|matching_task| matching_task.candidate_id <= index);
|
||||||
|
Some(index).and_then(|index| (index != 0).then(|| index - 1))
|
||||||
|
});
|
||||||
|
|
||||||
if delegate.matches.is_empty() {
|
if delegate.matches.is_empty() {
|
||||||
delegate.selected_index = 0;
|
delegate.selected_index = 0;
|
||||||
@ -352,7 +364,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||||||
})
|
})
|
||||||
.map(|item| {
|
.map(|item| {
|
||||||
let item = if matches!(source_kind, TaskSourceKind::UserInput)
|
let item = if matches!(source_kind, TaskSourceKind::UserInput)
|
||||||
|| Some(ix) <= self.last_used_candidate_index
|
|| Some(ix) <= self.divider_index
|
||||||
{
|
{
|
||||||
let task_index = hit.candidate_id;
|
let task_index = hit.candidate_id;
|
||||||
let delete_button = div().child(
|
let delete_button = div().child(
|
||||||
@ -412,7 +424,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn separators_after_indices(&self) -> Vec<usize> {
|
fn separators_after_indices(&self) -> Vec<usize> {
|
||||||
if let Some(i) = self.last_used_candidate_index {
|
if let Some(i) = self.divider_index {
|
||||||
vec![i]
|
vec![i]
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
|
Loading…
Reference in New Issue
Block a user