From 3b2fb417eac64105b70998839aee04a553253871 Mon Sep 17 00:00:00 2001 From: Danilo Leal Date: Sat, 20 Dec 2025 12:34:24 -0300 Subject: [PATCH] Move action to the workspace so I can use it from the pane --- crates/editor/src/actions.rs | 2 -- crates/editor/src/editor.rs | 7 ++++++- crates/workspace/src/workspace.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index ad3734f432b8f2a4a9540420e28ed276f6ea5d85..af370658fe0de57fce20932b71f9d3e1f9eb1831 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -845,8 +845,6 @@ actions!( UnwrapSyntaxNode, /// Wraps selections in tag specified by language. WrapSelectionsInTag, - /// Toggles read-only mode for the current buffer. - ToggleReadOnly, ] ); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a2d410bf06cee3e01dc712e9731261f9eba03f77..e5100d5190100f79e1b6a983290f985b017b7fc2 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -11007,7 +11007,12 @@ impl Editor { }); } - pub fn toggle_read_only(&mut self, _: &ToggleReadOnly, _: &mut Window, cx: &mut Context) { + pub fn toggle_read_only( + &mut self, + _: &workspace::ToggleReadOnlyFile, + _: &mut Window, + cx: &mut Context, + ) { if let Some(buffer) = self.buffer.read(cx).as_singleton() { buffer.update(cx, |buffer, cx| { buffer.set_capability( diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 53b0cc0623fa4b3ce7de5f1d8e3fd2262210a09a..73606f6887dd96773307bbf91170ceb6b81fa6ba 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -281,6 +281,8 @@ actions!( ToggleRightDock, /// Toggles zoom on the active pane. ToggleZoom, + /// Toggles read-only mode for the active item (if supported by that item). + ToggleReadOnlyFile, /// Zooms in on the active pane. ZoomIn, /// Zooms out of the active pane. @@ -6249,6 +6251,14 @@ impl Workspace { cx.propagate(); }, )) + .on_action( + cx.listener(|workspace, _: &ToggleReadOnlyFile, window, cx| { + let pane = workspace.active_pane().clone(); + if let Some(item) = pane.read(cx).active_item() { + item.toggle_read_only(window, cx); + } + }), + ) .on_action(cx.listener(Workspace::cancel)) }