Allow metadata to be associated with text written to clipboard
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
co-authored by
Max Brunsfeld
parent
f4c1ffc329
commit
13514aae6c
@@ -6,8 +6,8 @@ use crate::{settings::Settings, watch, workspace};
|
||||
use anyhow::Result;
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use gpui::{
|
||||
fonts::Properties as FontProperties, keymap::Binding, text_layout, AppContext, Element,
|
||||
ElementBox, Entity, FontCache, ModelHandle, MutableAppContext, View, ViewContext,
|
||||
fonts::Properties as FontProperties, keymap::Binding, text_layout, AppContext, ClipboardItem,
|
||||
Element, ElementBox, Entity, FontCache, ModelHandle, MutableAppContext, View, ViewContext,
|
||||
WeakViewHandle,
|
||||
};
|
||||
use gpui::{geometry::vector::Vector2F, TextLayoutCache};
|
||||
@@ -479,7 +479,7 @@ impl BufferView {
|
||||
self.insert(&String::new(), ctx);
|
||||
self.end_transaction(ctx);
|
||||
|
||||
ctx.app_mut().copy(&text);
|
||||
ctx.app_mut().write_to_clipboard(ClipboardItem::new(text));
|
||||
}
|
||||
|
||||
pub fn copy(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||
@@ -496,12 +496,12 @@ impl BufferView {
|
||||
text.extend(buffer.text_for_range(start..end).unwrap());
|
||||
}
|
||||
|
||||
ctx.app_mut().copy(&text);
|
||||
ctx.app_mut().write_to_clipboard(ClipboardItem::new(text));
|
||||
}
|
||||
|
||||
pub fn paste(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||
if let Some(text) = ctx.app_mut().paste() {
|
||||
self.insert(&text, ctx);
|
||||
if let Some(item) = ctx.app_mut().read_from_clipboard() {
|
||||
self.insert(item.text(), ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{settings::Settings, watch};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use gpui::{
|
||||
color::rgbu, elements::*, json::to_string_pretty, keymap::Binding, AnyViewHandle, AppContext,
|
||||
Entity, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle,
|
||||
ClipboardItem, Entity, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle,
|
||||
};
|
||||
use log::{error, info};
|
||||
use std::{collections::HashSet, path::PathBuf};
|
||||
@@ -258,10 +258,11 @@ impl WorkspaceView {
|
||||
pub fn debug_elements(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||
match to_string_pretty(&ctx.debug_elements()) {
|
||||
Ok(json) => {
|
||||
ctx.app_mut().copy(&json);
|
||||
let kib = json.len() as f32 / 1024.;
|
||||
ctx.app_mut().write_to_clipboard(ClipboardItem::new(json));
|
||||
log::info!(
|
||||
"copied {:.1} KiB of element debug JSON to the clipboard",
|
||||
json.len() as f32 / 1024.
|
||||
kib
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
|
||||
Reference in New Issue
Block a user