mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-23 23:09:42 +00:00
Fix editor::Cancel
action not inline assistant inputs created for empty selections (#16150)
Release Notes: - N/A
This commit is contained in:
parent
ee6a40137f
commit
b36d1386a9
1 changed files with 32 additions and 6 deletions
|
@ -532,17 +532,43 @@ impl InlineAssistant {
|
||||||
if editor.selections.count() == 1 {
|
if editor.selections.count() == 1 {
|
||||||
let selection = editor.selections.newest::<usize>(cx);
|
let selection = editor.selections.newest::<usize>(cx);
|
||||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||||
|
let mut closest_assist_fallback = None;
|
||||||
for assist_id in &editor_assists.assist_ids {
|
for assist_id in &editor_assists.assist_ids {
|
||||||
let assist = &self.assists[assist_id];
|
let assist = &self.assists[assist_id];
|
||||||
let assist_range = assist.range.to_offset(&buffer);
|
let assist_range = assist.range.to_offset(&buffer);
|
||||||
if assist.decorations.is_some()
|
if assist.decorations.is_some() {
|
||||||
&& assist_range.contains(&selection.start)
|
if assist_range.contains(&selection.start)
|
||||||
&& assist_range.contains(&selection.end)
|
&& assist_range.contains(&selection.end)
|
||||||
{
|
{
|
||||||
self.focus_assist(*assist_id, cx);
|
self.focus_assist(*assist_id, cx);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
let distance_from_selection = assist_range
|
||||||
|
.start
|
||||||
|
.abs_diff(selection.start)
|
||||||
|
.min(assist_range.start.abs_diff(selection.end))
|
||||||
|
+ assist_range
|
||||||
|
.end
|
||||||
|
.abs_diff(selection.start)
|
||||||
|
.min(assist_range.end.abs_diff(selection.end));
|
||||||
|
match closest_assist_fallback {
|
||||||
|
Some((_, old_distance)) => {
|
||||||
|
if distance_from_selection < old_distance {
|
||||||
|
closest_assist_fallback =
|
||||||
|
Some((assist_id, distance_from_selection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
closest_assist_fallback = Some((assist_id, distance_from_selection))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some((&assist_id, _)) = closest_assist_fallback {
|
||||||
|
self.focus_assist(assist_id, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.propagate();
|
cx.propagate();
|
||||||
|
|
Loading…
Reference in a new issue