Simplify focus management in AssistantPanel
This commit is contained in:
parent
e96197d63b
commit
02bd4fb1f1
1 changed files with 12 additions and 22 deletions
|
@ -331,7 +331,7 @@ impl AssistantPanel {
|
||||||
|
|
||||||
let measurements = Rc::new(Cell::new(BlockMeasurements::default()));
|
let measurements = Rc::new(Cell::new(BlockMeasurements::default()));
|
||||||
let inline_assistant = cx.build_view(|cx| {
|
let inline_assistant = cx.build_view(|cx| {
|
||||||
let assistant = InlineAssistant::new(
|
InlineAssistant::new(
|
||||||
inline_assist_id,
|
inline_assist_id,
|
||||||
measurements.clone(),
|
measurements.clone(),
|
||||||
self.include_conversation_in_next_inline_assist,
|
self.include_conversation_in_next_inline_assist,
|
||||||
|
@ -342,9 +342,7 @@ impl AssistantPanel {
|
||||||
self.retrieve_context_in_next_inline_assist,
|
self.retrieve_context_in_next_inline_assist,
|
||||||
self.semantic_index.clone(),
|
self.semantic_index.clone(),
|
||||||
project.clone(),
|
project.clone(),
|
||||||
);
|
)
|
||||||
assistant.focus_handle.focus(cx);
|
|
||||||
assistant
|
|
||||||
});
|
});
|
||||||
let block_id = editor.update(cx, |editor, cx| {
|
let block_id = editor.update(cx, |editor, cx| {
|
||||||
editor.change_selections(None, cx, |selections| {
|
editor.change_selections(None, cx, |selections| {
|
||||||
|
@ -391,10 +389,7 @@ impl AssistantPanel {
|
||||||
if let Some(inline_assistant) = inline_assistant.upgrade() {
|
if let Some(inline_assistant) = inline_assistant.upgrade() {
|
||||||
if let EditorEvent::SelectionsChanged { local } = event {
|
if let EditorEvent::SelectionsChanged { local } = event {
|
||||||
if *local
|
if *local
|
||||||
&& inline_assistant
|
&& inline_assistant.focus_handle(cx).contains_focused(cx)
|
||||||
.read(cx)
|
|
||||||
.focus_handle
|
|
||||||
.contains_focused(cx)
|
|
||||||
{
|
{
|
||||||
cx.focus_view(&editor);
|
cx.focus_view(&editor);
|
||||||
}
|
}
|
||||||
|
@ -553,9 +548,12 @@ impl AssistantPanel {
|
||||||
fn hide_inline_assist(&mut self, assist_id: usize, cx: &mut ViewContext<Self>) {
|
fn hide_inline_assist(&mut self, assist_id: usize, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(pending_assist) = self.pending_inline_assists.get_mut(&assist_id) {
|
if let Some(pending_assist) = self.pending_inline_assists.get_mut(&assist_id) {
|
||||||
if let Some(editor) = pending_assist.editor.upgrade() {
|
if let Some(editor) = pending_assist.editor.upgrade() {
|
||||||
if let Some((block_id, _)) = pending_assist.inline_assistant.take() {
|
if let Some((block_id, inline_assistant)) = pending_assist.inline_assistant.take() {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.remove_blocks(HashSet::from_iter([block_id]), None, cx);
|
editor.remove_blocks(HashSet::from_iter([block_id]), None, cx);
|
||||||
|
if inline_assistant.focus_handle(cx).contains_focused(cx) {
|
||||||
|
editor.focus(cx);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2029,7 +2027,6 @@ struct ConversationEditor {
|
||||||
editor: View<Editor>,
|
editor: View<Editor>,
|
||||||
blocks: HashSet<BlockId>,
|
blocks: HashSet<BlockId>,
|
||||||
scroll_position: Option<ScrollPosition>,
|
scroll_position: Option<ScrollPosition>,
|
||||||
focus_handle: FocusHandle,
|
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2060,13 +2057,10 @@ impl ConversationEditor {
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
|
||||||
let focus_handle = cx.focus_handle();
|
|
||||||
|
|
||||||
let _subscriptions = vec![
|
let _subscriptions = vec![
|
||||||
cx.observe(&conversation, |_, _, cx| cx.notify()),
|
cx.observe(&conversation, |_, _, cx| cx.notify()),
|
||||||
cx.subscribe(&conversation, Self::handle_conversation_event),
|
cx.subscribe(&conversation, Self::handle_conversation_event),
|
||||||
cx.subscribe(&editor, Self::handle_editor_event),
|
cx.subscribe(&editor, Self::handle_editor_event),
|
||||||
cx.on_focus(&focus_handle, |this, cx| cx.focus_view(&this.editor)),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
|
@ -2076,7 +2070,6 @@ impl ConversationEditor {
|
||||||
scroll_position: None,
|
scroll_position: None,
|
||||||
fs,
|
fs,
|
||||||
workspace,
|
workspace,
|
||||||
focus_handle,
|
|
||||||
_subscriptions,
|
_subscriptions,
|
||||||
};
|
};
|
||||||
this.update_message_headers(cx);
|
this.update_message_headers(cx);
|
||||||
|
@ -2487,8 +2480,8 @@ impl Render for ConversationEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FocusableView for ConversationEditor {
|
impl FocusableView for ConversationEditor {
|
||||||
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
|
||||||
self.focus_handle.clone()
|
self.editor.focus_handle(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2542,7 +2535,6 @@ struct InlineAssistant {
|
||||||
prompt_editor: View<Editor>,
|
prompt_editor: View<Editor>,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
confirmed: bool,
|
confirmed: bool,
|
||||||
focus_handle: FocusHandle,
|
|
||||||
include_conversation: bool,
|
include_conversation: bool,
|
||||||
measurements: Rc<Cell<BlockMeasurements>>,
|
measurements: Rc<Cell<BlockMeasurements>>,
|
||||||
prompt_history: VecDeque<String>,
|
prompt_history: VecDeque<String>,
|
||||||
|
@ -2638,8 +2630,8 @@ impl Render for InlineAssistant {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FocusableView for InlineAssistant {
|
impl FocusableView for InlineAssistant {
|
||||||
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
|
||||||
self.focus_handle.clone()
|
self.prompt_editor.focus_handle(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2665,12 +2657,11 @@ impl InlineAssistant {
|
||||||
editor.set_placeholder_text(placeholder, cx);
|
editor.set_placeholder_text(placeholder, cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
cx.focus_view(&prompt_editor);
|
||||||
|
|
||||||
let focus_handle = cx.focus_handle();
|
|
||||||
let mut subscriptions = vec![
|
let mut subscriptions = vec![
|
||||||
cx.observe(&codegen, Self::handle_codegen_changed),
|
cx.observe(&codegen, Self::handle_codegen_changed),
|
||||||
cx.subscribe(&prompt_editor, Self::handle_prompt_editor_events),
|
cx.subscribe(&prompt_editor, Self::handle_prompt_editor_events),
|
||||||
cx.on_focus(&focus_handle, |this, cx| cx.focus_view(&this.prompt_editor)),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if let Some(semantic_index) = semantic_index.clone() {
|
if let Some(semantic_index) = semantic_index.clone() {
|
||||||
|
@ -2682,7 +2673,6 @@ impl InlineAssistant {
|
||||||
prompt_editor,
|
prompt_editor,
|
||||||
workspace,
|
workspace,
|
||||||
confirmed: false,
|
confirmed: false,
|
||||||
focus_handle,
|
|
||||||
include_conversation,
|
include_conversation,
|
||||||
measurements,
|
measurements,
|
||||||
prompt_history,
|
prompt_history,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue