diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index ba36f88f6380ade2a0d70f0f7ac3eb221446b781..ad3734f432b8f2a4a9540420e28ed276f6ea5d85 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -844,7 +844,9 @@ actions!( /// from the current selections. UnwrapSyntaxNode, /// Wraps selections in tag specified by language. - WrapSelectionsInTag + 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 7413af66149784c2e990e9a0731eba04c1bd5886..12d47557f09064cb091fd901803cbcfd82cacb09 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -11007,6 +11007,21 @@ impl Editor { }); } + pub fn toggle_read_only(&mut self, _: &ToggleReadOnly, _: &mut Window, cx: &mut Context) { + // todo(lw): We should not allow toggling every editor to read-write. Some we want to keep read-only, always as they might be read-only replicated etc. + if let Some(buffer) = self.buffer.read(cx).as_singleton() { + buffer.update(cx, |buffer, cx| { + buffer.set_capability( + match buffer.capability() { + Capability::ReadWrite => Capability::ReadOnly, + Capability::ReadOnly => Capability::ReadWrite, + }, + cx, + ); + }) + } + } + pub fn reload_file(&mut self, _: &ReloadFile, window: &mut Window, cx: &mut Context) { let Some(project) = self.project.clone() else { return; diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index a658b4616c4c429ec27b63931790a54ccd71cfa6..38e809dfbdeeb93281439e189c541f3909474a2d 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -615,6 +615,7 @@ impl EditorElement { register_action(editor, window, Editor::edit_log_breakpoint); register_action(editor, window, Editor::enable_breakpoint); register_action(editor, window, Editor::disable_breakpoint); + register_action(editor, window, Editor::toggle_read_only); if editor.read(cx).enable_wrap_selections_in_tag(cx) { register_action(editor, window, Editor::wrap_selections_in_tag); }