Update placeholder text with key bindings to focus context panel and navigate history (#19447)
Hopefully, this will help people understand how easy it is to add context to an inline transformation.  @as-cii @maxdeviant @rtfeldman could somebody update this to display the actual correct key bindings and ship it. I have them hard coded for now. Release Notes: - Updated placeholder text with key bindings to focus context panel and navigate history. --------- Co-authored-by: Richard Feldman <oss@rtfeldman.com>
This commit is contained in:
parent
85bdd9329b
commit
24cb694494
3 changed files with 22 additions and 5 deletions
|
@ -54,7 +54,7 @@ use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
|
||||||
use terminal_view::terminal_panel::TerminalPanel;
|
use terminal_view::terminal_panel::TerminalPanel;
|
||||||
use text::{OffsetRangeExt, ToPoint as _};
|
use text::{OffsetRangeExt, ToPoint as _};
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, CheckboxWithLabel, IconButtonShape, Popover, Tooltip};
|
use ui::{prelude::*, text_for_action, CheckboxWithLabel, IconButtonShape, Popover, Tooltip};
|
||||||
use util::{RangeExt, ResultExt};
|
use util::{RangeExt, ResultExt};
|
||||||
use workspace::{notifications::NotificationId, ItemHandle, Toast, Workspace};
|
use workspace::{notifications::NotificationId, ItemHandle, Toast, Workspace};
|
||||||
|
|
||||||
|
@ -1596,7 +1596,7 @@ impl PromptEditor {
|
||||||
// always show the cursor (even when it isn't focused) because
|
// always show the cursor (even when it isn't focused) because
|
||||||
// typing in one will make what you typed appear in all of them.
|
// typing in one will make what you typed appear in all of them.
|
||||||
editor.set_show_cursor_when_unfocused(true, cx);
|
editor.set_show_cursor_when_unfocused(true, cx);
|
||||||
editor.set_placeholder_text("Add a prompt…", cx);
|
editor.set_placeholder_text(Self::placeholder_text(codegen.read(cx), cx), cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1653,6 +1653,7 @@ impl PromptEditor {
|
||||||
self.editor = cx.new_view(|cx| {
|
self.editor = cx.new_view(|cx| {
|
||||||
let mut editor = Editor::auto_height(Self::MAX_LINES as usize, cx);
|
let mut editor = Editor::auto_height(Self::MAX_LINES as usize, cx);
|
||||||
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
|
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
|
||||||
|
editor.set_placeholder_text(Self::placeholder_text(self.codegen.read(cx), cx), cx);
|
||||||
editor.set_placeholder_text("Add a prompt…", cx);
|
editor.set_placeholder_text("Add a prompt…", cx);
|
||||||
editor.set_text(prompt, cx);
|
editor.set_text(prompt, cx);
|
||||||
if focus {
|
if focus {
|
||||||
|
@ -1663,6 +1664,20 @@ impl PromptEditor {
|
||||||
self.subscribe_to_editor(cx);
|
self.subscribe_to_editor(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn placeholder_text(codegen: &Codegen, cx: &WindowContext) -> String {
|
||||||
|
let context_keybinding = text_for_action(&crate::ToggleFocus, cx)
|
||||||
|
.map(|keybinding| format!(" • {keybinding} for context"))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let action = if codegen.is_insertion {
|
||||||
|
"Generate"
|
||||||
|
} else {
|
||||||
|
"Transform"
|
||||||
|
};
|
||||||
|
|
||||||
|
format!("{action}…{context_keybinding} • ↓↑ for history")
|
||||||
|
}
|
||||||
|
|
||||||
fn prompt(&self, cx: &AppContext) -> String {
|
fn prompt(&self, cx: &AppContext) -> String {
|
||||||
self.editor.read(cx).text(cx)
|
self.editor.read(cx).text(cx)
|
||||||
}
|
}
|
||||||
|
@ -2260,6 +2275,7 @@ pub struct Codegen {
|
||||||
initial_transaction_id: Option<TransactionId>,
|
initial_transaction_id: Option<TransactionId>,
|
||||||
telemetry: Option<Arc<Telemetry>>,
|
telemetry: Option<Arc<Telemetry>>,
|
||||||
builder: Arc<PromptBuilder>,
|
builder: Arc<PromptBuilder>,
|
||||||
|
is_insertion: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Codegen {
|
impl Codegen {
|
||||||
|
@ -2282,6 +2298,7 @@ impl Codegen {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
|
is_insertion: range.to_offset(&buffer.read(cx).snapshot(cx)).is_empty(),
|
||||||
alternatives: vec![codegen],
|
alternatives: vec![codegen],
|
||||||
active_alternative: 0,
|
active_alternative: 0,
|
||||||
seen_alternatives: HashSet::default(),
|
seen_alternatives: HashSet::default(),
|
||||||
|
@ -2683,7 +2700,7 @@ impl CodegenAlternative {
|
||||||
|
|
||||||
let prompt = self
|
let prompt = self
|
||||||
.builder
|
.builder
|
||||||
.generate_content_prompt(user_prompt, language_name, buffer, range)
|
.generate_inline_transformation_prompt(user_prompt, language_name, buffer, range)
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to generate content prompt: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to generate content prompt: {}", e))?;
|
||||||
|
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
|
|
@ -204,7 +204,7 @@ impl PromptBuilder {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_content_prompt(
|
pub fn generate_inline_transformation_prompt(
|
||||||
&self,
|
&self,
|
||||||
user_prompt: String,
|
user_prompt: String,
|
||||||
language_name: Option<&LanguageName>,
|
language_name: Option<&LanguageName>,
|
||||||
|
|
|
@ -196,7 +196,7 @@ impl KeyIcon {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a textual representation of the key binding for the given [`Action`].
|
/// Returns a textual representation of the key binding for the given [`Action`].
|
||||||
pub fn text_for_action(action: &dyn Action, cx: &mut WindowContext) -> Option<String> {
|
pub fn text_for_action(action: &dyn Action, cx: &WindowContext) -> Option<String> {
|
||||||
let key_binding = cx.bindings_for_action(action).last().cloned()?;
|
let key_binding = cx.bindings_for_action(action).last().cloned()?;
|
||||||
Some(text_for_key_binding(key_binding, PlatformStyle::platform()))
|
Some(text_for_key_binding(key_binding, PlatformStyle::platform()))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue