mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Add placeholder text for inline assistant prompts
This commit is contained in:
parent
b101a7edff
commit
75a6a94e96
1 changed files with 22 additions and 21 deletions
|
@ -249,15 +249,21 @@ impl AssistantPanel {
|
||||||
let selection = editor.read(cx).selections.newest_anchor().clone();
|
let selection = editor.read(cx).selections.newest_anchor().clone();
|
||||||
let range = selection.start.bias_left(&snapshot)..selection.end.bias_right(&snapshot);
|
let range = selection.start.bias_left(&snapshot)..selection.end.bias_right(&snapshot);
|
||||||
let assist_kind = if editor.read(cx).selections.newest::<usize>(cx).is_empty() {
|
let assist_kind = if editor.read(cx).selections.newest::<usize>(cx).is_empty() {
|
||||||
InlineAssistKind::Insert
|
InlineAssistKind::Generate
|
||||||
} else {
|
} else {
|
||||||
InlineAssistKind::Refactor
|
InlineAssistKind::Transform
|
||||||
};
|
};
|
||||||
let prompt_editor = cx.add_view(|cx| {
|
let prompt_editor = cx.add_view(|cx| {
|
||||||
Editor::single_line(
|
let mut editor = Editor::single_line(
|
||||||
Some(Arc::new(|theme| theme.assistant.inline.editor.clone())),
|
Some(Arc::new(|theme| theme.assistant.inline.editor.clone())),
|
||||||
cx,
|
cx,
|
||||||
)
|
);
|
||||||
|
let placeholder = match assist_kind {
|
||||||
|
InlineAssistKind::Transform => "Enter transformation prompt…",
|
||||||
|
InlineAssistKind::Generate => "Enter generation prompt…",
|
||||||
|
};
|
||||||
|
editor.set_placeholder_text(placeholder, cx);
|
||||||
|
editor
|
||||||
});
|
});
|
||||||
let inline_assistant = cx.add_view(|cx| {
|
let inline_assistant = cx.add_view(|cx| {
|
||||||
let assistant = InlineAssistant {
|
let assistant = InlineAssistant {
|
||||||
|
@ -284,12 +290,12 @@ impl AssistantPanel {
|
||||||
render: Arc::new({
|
render: Arc::new({
|
||||||
let inline_assistant = inline_assistant.clone();
|
let inline_assistant = inline_assistant.clone();
|
||||||
move |cx: &mut BlockContext| {
|
move |cx: &mut BlockContext| {
|
||||||
|
let theme = theme::current(cx);
|
||||||
ChildView::new(&inline_assistant, cx)
|
ChildView::new(&inline_assistant, cx)
|
||||||
.contained()
|
.contained()
|
||||||
.with_padding_left(match assist_kind {
|
.with_padding_left(cx.anchor_x)
|
||||||
InlineAssistKind::Refactor => cx.gutter_width,
|
.contained()
|
||||||
InlineAssistKind::Insert => cx.anchor_x,
|
.with_style(theme.assistant.inline.container)
|
||||||
})
|
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -525,7 +531,7 @@ impl AssistantPanel {
|
||||||
let mut prompt = String::new();
|
let mut prompt = String::new();
|
||||||
writeln!(prompt, "You're an expert {language_name} engineer.").unwrap();
|
writeln!(prompt, "You're an expert {language_name} engineer.").unwrap();
|
||||||
match pending_assist.kind {
|
match pending_assist.kind {
|
||||||
InlineAssistKind::Refactor => {
|
InlineAssistKind::Transform => {
|
||||||
writeln!(
|
writeln!(
|
||||||
prompt,
|
prompt,
|
||||||
"You're currently working inside an editor on this code:"
|
"You're currently working inside an editor on this code:"
|
||||||
|
@ -557,7 +563,7 @@ impl AssistantPanel {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
InlineAssistKind::Insert => {
|
InlineAssistKind::Generate => {
|
||||||
writeln!(
|
writeln!(
|
||||||
prompt,
|
prompt,
|
||||||
"You're currently working inside an editor on this code:"
|
"You're currently working inside an editor on this code:"
|
||||||
|
@ -2775,8 +2781,8 @@ enum InlineAssistantEvent {
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
enum InlineAssistKind {
|
enum InlineAssistKind {
|
||||||
Refactor,
|
Transform,
|
||||||
Insert,
|
Generate,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InlineAssistant {
|
struct InlineAssistant {
|
||||||
|
@ -2797,15 +2803,10 @@ impl View for InlineAssistant {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||||
let theme = theme::current(cx);
|
ChildView::new(&self.prompt_editor, cx)
|
||||||
let prompt_editor = ChildView::new(&self.prompt_editor, cx).aligned().left();
|
.aligned()
|
||||||
match self.assist_kind {
|
.left()
|
||||||
InlineAssistKind::Refactor => prompt_editor
|
.into_any()
|
||||||
.contained()
|
|
||||||
.with_style(theme.assistant.inline.container)
|
|
||||||
.into_any(),
|
|
||||||
InlineAssistKind::Insert => prompt_editor.into_any(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Reference in a new issue