mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-01 12:07:14 +03:00
Forbid paste, undo, redo on read-only editors
This commit is contained in:
parent
14f6ed8fea
commit
7dc28aad78
@ -5443,6 +5443,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn paste(&mut self, _: &Paste, cx: &mut ViewContext<Self>) {
|
pub fn paste(&mut self, _: &Paste, cx: &mut ViewContext<Self>) {
|
||||||
|
if self.read_only(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.transact(cx, |this, cx| {
|
self.transact(cx, |this, cx| {
|
||||||
if let Some(item) = cx.read_from_clipboard() {
|
if let Some(item) = cx.read_from_clipboard() {
|
||||||
let clipboard_text = Cow::Borrowed(item.text());
|
let clipboard_text = Cow::Borrowed(item.text());
|
||||||
@ -5515,6 +5519,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn undo(&mut self, _: &Undo, cx: &mut ViewContext<Self>) {
|
pub fn undo(&mut self, _: &Undo, cx: &mut ViewContext<Self>) {
|
||||||
|
if self.read_only(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.undo(cx)) {
|
if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.undo(cx)) {
|
||||||
if let Some((selections, _)) = self.selection_history.transaction(tx_id).cloned() {
|
if let Some((selections, _)) = self.selection_history.transaction(tx_id).cloned() {
|
||||||
self.change_selections(None, cx, |s| {
|
self.change_selections(None, cx, |s| {
|
||||||
@ -5529,6 +5537,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn redo(&mut self, _: &Redo, cx: &mut ViewContext<Self>) {
|
pub fn redo(&mut self, _: &Redo, cx: &mut ViewContext<Self>) {
|
||||||
|
if self.read_only(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.redo(cx)) {
|
if let Some(tx_id) = self.buffer.update(cx, |buffer, cx| buffer.redo(cx)) {
|
||||||
if let Some((_, Some(selections))) = self.selection_history.transaction(tx_id).cloned()
|
if let Some((_, Some(selections))) = self.selection_history.transaction(tx_id).cloned()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user