Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Polish prompt library some more (#12686)
Antonio Scandurra6bbe9a225315
diff --git a/crates/assistant/src/prompt_library.rs b/crates/assistant/src/prompt_library.rsindex b42d828a10d..7352e2a06e4 100644--- a/crates/assistant/src/prompt_library.rs+++ b/crates/assistant/src/prompt_library.rs@@ -6,7 +6,7 @@ use anyhow::{anyhow, Result};use assistant_slash_command::SlashCommandRegistry;use chrono::{DateTime, Utc};use collections::HashMap;-use editor::{actions::Tab, Editor, EditorEvent};+use editor::{actions::Tab, CurrentLineHighlight, Editor, EditorEvent};use futures::{future::{self, BoxFuture, Shared},FutureExt,@@ -125,7 +125,7 @@ struct PromptPickerDelegate {}enum PromptPickerEvent {- Selected { prompt_id: PromptId },+ Selected { prompt_id: Option<PromptId> },Confirmed { prompt_id: PromptId },Deleted { prompt_id: PromptId },ToggledDefault { prompt_id: PromptId },@@ -164,11 +164,14 @@ impl PickerDelegate for PromptPickerDelegate {fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {self.selected_index = ix;- if let Some(PromptPickerEntry::Prompt(prompt)) = self.entries.get(self.selected_index) {- cx.emit(PromptPickerEvent::Selected {- prompt_id: prompt.id,- });- }+ let prompt_id = if let Some(PromptPickerEntry::Prompt(prompt)) =+ self.entries.get(self.selected_index)+ {+ Some(prompt.id)+ } else {+ None+ };+ cx.emit(PromptPickerEvent::Selected { prompt_id });}fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {@@ -355,7 +358,11 @@ impl PromptLibrary {) {match event {PromptPickerEvent::Selected { prompt_id } => {- self.load_prompt(*prompt_id, false, cx);+ if let Some(prompt_id) = *prompt_id {+ self.load_prompt(prompt_id, false, cx);+ } else {+ self.focus_picker(&Default::default(), cx);+ }}PromptPickerEvent::Confirmed { prompt_id } => {self.load_prompt(*prompt_id, true, cx);@@ -499,6 +506,7 @@ impl PromptLibrary {editor.set_show_gutter(false, cx);editor.set_show_wrap_guides(false, cx);editor.set_show_indent_guides(false, cx);+ editor.set_current_line_highlight(Some(CurrentLineHighlight::None));editor.set_completion_provider(Box::new(SlashCommandCompletionProvider::new(commands, None, None),));diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 51e0ae81e70..5ab32937356 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -53,8 +53,7 @@ use convert_case::{Case, Casing};use debounced_delay::DebouncedDelay;use display_map::*;pub use display_map::{DisplayPoint, FoldPlaceholder};-use editor_settings::CurrentLineHighlight;-pub use editor_settings::EditorSettings;+pub use editor_settings::{CurrentLineHighlight, EditorSettings};use element::LineWithInvisibles;pub use element::{CursorLayout, EditorElement, HighlightedRange, HighlightedRangeLine, PointForPosition,@@ -480,7 +479,7 @@ pub struct Editor {pending_rename: Option<RenameState>,searchable: bool,cursor_shape: CursorShape,- current_line_highlight: CurrentLineHighlight,+ current_line_highlight: Option<CurrentLineHighlight>,collapse_matches: bool,autoindent_mode: Option<AutoindentMode>,workspace: Option<(WeakView<Workspace>, Option<WorkspaceId>)>,@@ -1768,7 +1767,7 @@ impl Editor {pending_rename: Default::default(),searchable: true,cursor_shape: Default::default(),- current_line_highlight: EditorSettings::get_global(cx).current_line_highlight,+ current_line_highlight: None,autoindent_mode: Some(AutoindentMode::EachLine),collapse_matches: false,workspace: None,@@ -1992,7 +1991,9 @@ impl Editor {ongoing_scroll: self.scroll_manager.ongoing_scroll(),placeholder_text: self.placeholder_text.clone(),is_focused: self.focus_handle.is_focused(cx),- current_line_highlight: self.current_line_highlight,+ current_line_highlight: self+ .current_line_highlight+ .unwrap_or_else(|| EditorSettings::get_global(cx).current_line_highlight),gutter_hovered: self.gutter_hovered,}}@@ -2082,7 +2083,10 @@ impl Editor {cx.notify();}- pub fn set_current_line_highlight(&mut self, current_line_highlight: CurrentLineHighlight) {+ pub fn set_current_line_highlight(+ &mut self,+ current_line_highlight: Option<CurrentLineHighlight>,+ ) {self.current_line_highlight = current_line_highlight;}@@ -10608,7 +10612,6 @@ impl Editor {let editor_settings = EditorSettings::get_global(cx);self.scroll_manager.vertical_scroll_margin = editor_settings.vertical_scroll_margin;self.show_breadcrumbs = editor_settings.toolbar.breadcrumbs;- self.current_line_highlight = editor_settings.current_line_highlight;if self.mode == EditorMode::Full {let inline_blame_enabled = ProjectSettings::get_global(cx).git.inline_blame_enabled();diff --git a/crates/editor/src/hunk_diff.rs b/crates/editor/src/hunk_diff.rsindex a2fa4521c65..09b2c6482b5 100644--- a/crates/editor/src/hunk_diff.rs+++ b/crates/editor/src/hunk_diff.rs@@ -10,7 +10,7 @@ use language::Buffer;use multi_buffer::{Anchor, ExcerptRange, MultiBuffer, MultiBufferRow, MultiBufferSnapshot, ToPoint,};-use settings::{Settings, SettingsStore};+use settings::SettingsStore;use text::{BufferId, Point};use ui::{div, ActiveTheme, Context as _, IntoElement, ParentElement, Styled, ViewContext, VisualContext,@@ -21,7 +21,7 @@ use crate::{editor_settings::CurrentLineHighlight,git::{diff_hunk_to_display, DisplayDiffHunk},hunk_status, hunks_for_selections, BlockDisposition, BlockId, BlockProperties, BlockStyle,- DiffRowHighlight, Editor, EditorSettings, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt,+ DiffRowHighlight, Editor, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt,RevertSelectedHunks, ToDisplayPoint, ToggleHunkDiff,};@@ -591,7 +591,7 @@ fn editor_with_deleted_text(let subscription_editor = parent_editor.clone();editor._subscriptions.extend([cx.on_blur(&editor.focus_handle, |editor, cx| {- editor.set_current_line_highlight(CurrentLineHighlight::None);+ editor.set_current_line_highlight(Some(CurrentLineHighlight::None));editor.change_selections(None, cx, |s| {s.try_cancel();});@@ -602,14 +602,14 @@ fn editor_with_deleted_text({parent_editor.read(cx).current_line_highlight} else {- EditorSettings::get_global(cx).current_line_highlight+ None};editor.set_current_line_highlight(restored_highlight);cx.notify();}),cx.observe_global::<SettingsStore>(|editor, cx| {if !editor.is_focused(cx) {- editor.set_current_line_highlight(CurrentLineHighlight::None);+ editor.set_current_line_highlight(Some(CurrentLineHighlight::None));}}),]);