forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Add embedded surface policies for Cherrypick file editor #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83cb7b2
feat: curate embedded project panel and editor UI for Cherrypick
ps49developer 50b53ac
Merge remote-tracking branch 'upstream/main' into feat/code-editor
soyboyscout 892b325
fix: harden embedded surface policies
soyboyscout ed2b79d
feat: expose editor selection controls
soyboyscout 04f0c18
refactor: keep selection controls core reusable
soyboyscout 1637c43
fix: avoid editor churn in selection controls
soyboyscout ce7366d
Expose file finder hooks for embedded workspaces
soyboyscout c1ebeef
Fix selection controls toolbar updates
soyboyscout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ mod persistence; | |
| mod runnables; | ||
| mod rust_analyzer_ext; | ||
| pub mod scroll; | ||
| pub mod selection_controls; | ||
| mod selections_collection; | ||
| pub mod semantic_tokens; | ||
| mod split; | ||
|
|
@@ -594,6 +595,50 @@ pub struct ContextMenuOptions { | |
| pub placement: Option<ContextMenuPlacement>, | ||
| } | ||
|
|
||
| /// Controls which context-menu action groups are shown for an editor surface. | ||
| /// | ||
| /// The default policy preserves normal Zed behavior. Embedded hosts, such as | ||
| /// Cherrypick, can install a restricted policy when the host owns those actions | ||
| /// or intentionally omits them from its file-editor surface. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub struct EditorSurfacePolicy { | ||
| pub show_language_actions: bool, | ||
| pub show_agent_actions: bool, | ||
| pub show_preview_actions: bool, | ||
| pub show_terminal_actions: bool, | ||
| pub show_git_actions: bool, | ||
| } | ||
|
|
||
| impl EditorSurfacePolicy { | ||
| /// Shows every action group used by the standard Zed editor. | ||
| pub const fn full() -> Self { | ||
| Self { | ||
| show_language_actions: true, | ||
| show_agent_actions: true, | ||
| show_preview_actions: true, | ||
| show_terminal_actions: true, | ||
| show_git_actions: true, | ||
| } | ||
| } | ||
|
|
||
| /// Hides action groups that are handled by, or unavailable in, an embedded host. | ||
| pub const fn embedded() -> Self { | ||
| Self { | ||
| show_language_actions: false, | ||
| show_agent_actions: false, | ||
| show_preview_actions: false, | ||
| show_terminal_actions: false, | ||
| show_git_actions: false, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Default for EditorSurfacePolicy { | ||
| fn default() -> Self { | ||
| Self::full() | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum ContextMenuPlacement { | ||
| Above, | ||
|
|
@@ -1080,6 +1125,7 @@ pub struct Editor { | |
| show_selection_menu: Option<bool>, | ||
| blame: Option<Entity<GitBlame>>, | ||
| blame_subscription: Option<Subscription>, | ||
| surface_policy: EditorSurfacePolicy, | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| custom_context_menu: Option< | ||
| Box< | ||
| dyn 'static | ||
|
|
@@ -1736,6 +1782,7 @@ impl Editor { | |
| clone.needs_initial_data_update = self.enable_lsp_data; | ||
| clone.enable_runnables = self.enable_runnables; | ||
| clone.enable_code_lens = self.enable_code_lens; | ||
| clone.surface_policy = self.surface_policy; | ||
| clone | ||
| } | ||
|
|
||
|
|
@@ -2305,6 +2352,7 @@ impl Editor { | |
| }), | ||
| blame: None, | ||
| blame_subscription: None, | ||
| surface_policy: EditorSurfacePolicy::default(), | ||
|
|
||
| bookmark_store, | ||
| breakpoint_store, | ||
|
|
@@ -2730,11 +2778,15 @@ impl Editor { | |
| _: &mut Window, | ||
| cx: &mut Context<Self>, | ||
| ) { | ||
| let was_enabled = self.selection_menu_enabled(cx); | ||
| self.show_selection_menu = self | ||
| .show_selection_menu | ||
| .map(|show_selections_menu| !show_selections_menu) | ||
| .or_else(|| Some(!EditorSettings::get_global(cx).toolbar.selections_menu)); | ||
|
|
||
| if self.selection_menu_enabled(cx) != was_enabled { | ||
| cx.emit(EditorEvent::SelectionMenuChanged); | ||
| } | ||
| cx.notify(); | ||
| } | ||
|
|
||
|
|
@@ -2964,6 +3016,18 @@ impl Editor { | |
| self.in_project_search = in_project_search; | ||
| } | ||
|
|
||
| /// Updates context-menu action visibility for this editor surface. | ||
| /// | ||
| /// Standalone Zed leaves the default policy in place; embedded hosts call | ||
| /// this to hide actions that the host owns or does not expose. | ||
| pub fn set_surface_policy(&mut self, policy: EditorSurfacePolicy, cx: &mut Context<Self>) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| if self.surface_policy == policy { | ||
| return; | ||
| } | ||
| self.surface_policy = policy; | ||
| cx.notify(); | ||
| } | ||
|
|
||
| pub fn set_custom_context_menu( | ||
| &mut self, | ||
| f: impl 'static | ||
|
|
@@ -11628,6 +11692,7 @@ pub enum EditorEvent { | |
| Saved, | ||
| TitleChanged, | ||
| FileHandleChanged, | ||
| SelectionMenuChanged, | ||
| SelectionsChanged { | ||
| local: bool, | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.