@@ -205,8 +205,9 @@ pub fn deploy_context_menu(
205205 . all :: < PointUtf16 > ( & display_map)
206206 . into_iter ( )
207207 . any ( |s| !s. is_empty ( ) ) ;
208- let has_git_repo =
209- buffer
208+ let surface_policy = editor. surface_policy ;
209+ let has_git_repo = surface_policy. show_git_actions
210+ && buffer
210211 . anchor_to_buffer_anchor ( anchor)
211212 . is_some_and ( |( buffer_anchor, _) | {
212213 project
@@ -225,23 +226,25 @@ pub fn deploy_context_menu(
225226 cx,
226227 ) ;
227228
228- let is_markdown = editor
229- . buffer ( )
230- . read ( cx)
231- . as_singleton ( )
232- . and_then ( |buffer| buffer. read ( cx) . language ( ) )
233- . is_some_and ( |language| language. name ( ) . as_ref ( ) == "Markdown" ) ;
229+ let is_markdown = surface_policy. show_preview_actions
230+ && editor
231+ . buffer ( )
232+ . read ( cx)
233+ . as_singleton ( )
234+ . and_then ( |buffer| buffer. read ( cx) . language ( ) )
235+ . is_some_and ( |language| language. name ( ) . as_ref ( ) == "Markdown" ) ;
234236
235- let is_svg = editor
236- . buffer ( )
237- . read ( cx)
238- . as_singleton ( )
239- . and_then ( |buffer| buffer. read ( cx) . file ( ) )
240- . is_some_and ( |file| {
241- std:: path:: Path :: new ( file. file_name ( cx) )
242- . extension ( )
243- . is_some_and ( |ext| ext. eq_ignore_ascii_case ( "svg" ) )
244- } ) ;
237+ let is_svg = surface_policy. show_preview_actions
238+ && editor
239+ . buffer ( )
240+ . read ( cx)
241+ . as_singleton ( )
242+ . and_then ( |buffer| buffer. read ( cx) . file ( ) )
243+ . is_some_and ( |file| {
244+ std:: path:: Path :: new ( file. file_name ( cx) )
245+ . extension ( )
246+ . is_some_and ( |extension| extension. eq_ignore_ascii_case ( "svg" ) )
247+ } ) ;
245248
246249 ui:: ContextMenu :: build ( window, cx, |menu, _window, _cx| {
247250 let builder = menu
@@ -256,31 +259,39 @@ pub fn deploy_context_menu(
256259 run_to_cursor || ( evaluate_selection && has_selections) ,
257260 |builder| builder. separator ( ) ,
258261 )
259- . action ( "Go to Definition" , Box :: new ( GoToDefinition ) )
260- . action ( "Go to Declaration" , Box :: new ( GoToDeclaration ) )
261- . action ( "Go to Type Definition" , Box :: new ( GoToTypeDefinition ) )
262- . action ( "Go to Implementation" , Box :: new ( GoToImplementation ) )
263- . action (
264- "Find All References" ,
265- Box :: new ( FindAllReferences :: default ( ) ) ,
266- )
267- . separator ( )
268- . action ( "Rename Symbol" , Box :: new ( Rename ) )
269- . action ( "Format Buffer" , Box :: new ( Format ) )
270- . when ( format_selections, |cx| {
271- cx. action ( "Format Selections" , Box :: new ( FormatSelections ) )
262+ . when ( surface_policy. show_language_actions , |builder| {
263+ builder
264+ . action ( "Go to Definition" , Box :: new ( GoToDefinition ) )
265+ . action ( "Go to Declaration" , Box :: new ( GoToDeclaration ) )
266+ . action ( "Go to Type Definition" , Box :: new ( GoToTypeDefinition ) )
267+ . action ( "Go to Implementation" , Box :: new ( GoToImplementation ) )
268+ . action (
269+ "Find All References" ,
270+ Box :: new ( FindAllReferences :: default ( ) ) ,
271+ )
272+ . separator ( )
273+ . action ( "Rename Symbol" , Box :: new ( Rename ) )
274+ . action ( "Format Buffer" , Box :: new ( Format ) )
275+ . when ( format_selections, |cx| {
276+ cx. action ( "Format Selections" , Box :: new ( FormatSelections ) )
277+ } )
278+ . action (
279+ "Show Code Actions" ,
280+ Box :: new ( ToggleCodeActions {
281+ deployed_from : None ,
282+ quick_launch : false ,
283+ } ) ,
284+ )
272285 } )
273- . action (
274- "Show Code Actions" ,
275- Box :: new ( ToggleCodeActions {
276- deployed_from : None ,
277- quick_launch : false ,
278- } ) ,
286+ . when (
287+ surface_policy. show_agent_actions && !disable_ai && has_selections,
288+ |this| this. action ( "Add to Agent Thread" , Box :: new ( AddSelectionToThread ) ) ,
289+ )
290+ . when (
291+ surface_policy. show_language_actions
292+ || ( surface_policy. show_agent_actions && !disable_ai && has_selections) ,
293+ |builder| builder. separator ( ) ,
279294 )
280- . when ( !disable_ai && has_selections, |this| {
281- this. action ( "Add to Agent Thread" , Box :: new ( AddSelectionToThread ) )
282- } )
283- . separator ( )
284295 . action ( "Cut" , Box :: new ( Cut ) )
285296 . action ( "Copy" , Box :: new ( Copy ) )
286297 . action ( "Copy and Trim" , Box :: new ( CopyAndTrim ) )
@@ -297,21 +308,26 @@ pub fn deploy_context_menu(
297308 . when ( is_svg, |builder| {
298309 builder. action ( "Open SVG Preview" , Box :: new ( OpenSvgPreview ) )
299310 } )
300- . action_disabled_when (
301- !has_reveal_target,
302- "Open in Terminal" ,
303- Box :: new ( OpenInTerminal ) ,
304- )
305- . action_disabled_when (
306- !has_git_repo,
307- "Copy Permalink" ,
308- Box :: new ( CopyPermalinkToLine ) ,
309- )
310- . action_disabled_when (
311- !has_git_repo,
312- "View File History" ,
313- Box :: new ( git:: FileHistory ) ,
314- ) ;
311+ . when ( surface_policy. show_terminal_actions , |builder| {
312+ builder. action_disabled_when (
313+ !has_reveal_target,
314+ "Open in Terminal" ,
315+ Box :: new ( OpenInTerminal ) ,
316+ )
317+ } )
318+ . when ( surface_policy. show_git_actions , |builder| {
319+ builder
320+ . action_disabled_when (
321+ !has_git_repo,
322+ "Copy Permalink" ,
323+ Box :: new ( CopyPermalinkToLine ) ,
324+ )
325+ . action_disabled_when (
326+ !has_git_repo,
327+ "View File History" ,
328+ Box :: new ( git:: FileHistory ) ,
329+ )
330+ } ) ;
315331 match focus {
316332 Some ( focus) => builder. context ( focus) ,
317333 None => builder,
0 commit comments