T44d Web · Hidden demos keep still, wide ones scroll whole, pastes read the web's clipboard

This commit is contained in:
ZacharyZhang-NY committed 2026-09-29 22:13:27 -04:00
1 parent d2018f8510
commit 752e7cba0c
26 files changed
+211 -101

No files matched your search

+22 -10
View File
@@ -1,6 +1,9 @@
use std::rc::Rc;
use gpui::{App, ClipboardItem, Entity, KeyDownEvent, Pixels, Point, SharedString, Window, point};
use anyhow::anyhow;
use gpui::{
App, ClipboardItem, Entity, KeyDownEvent, Pixels, Point, SharedString, TaskExt, Window, point,
};
use super::{
formula::filled,
@@ -283,15 +286,24 @@ pub(crate) fn keys(
sheet.read(cx),
))),
("v", true) => {
let Some(text) = cx.read_from_clipboard().and_then(|item| item.text()) else {
log::info!("grid: the clipboard holds no text to paste");
return;
};
let edits = pasted(&text, (row, col), (rows, cols));
log::info!("grid: pasted {} cells", edits.len());
if let Some(on_change) = &face.on_change {
on_change(&edits, window, cx);
}
// The web reads its clipboard only through the async reader.
let read = cx.read_from_clipboard_async();
let on_change = face.on_change.clone();
window
.spawn(cx, async move |cx| {
let item = read.await.map_err(|error| anyhow!("{error:?}"))?;
let Some(text) = item.and_then(|item| item.text()) else {
log::info!("grid: the clipboard holds no text to paste");
return Ok(());
};
let edits = pasted(&text, (row, col), (rows, cols));
log::info!("grid: pasted {} cells", edits.len());
if let Some(on_change) = on_change {
cx.update(|window, cx| on_change(&edits, window, cx))?;
}
anyhow::Ok(())
})
.detach_and_log_err(cx);
}
_ => {
let typed = stroke.key_char.clone().filter(|typed| {
+33
View File
@@ -0,0 +1,33 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{ClipboardItem, Modifiers, TestAppContext, point, px};
use super::{Grid, settle};
use crate::theme::Theme;
#[gpui::test]
fn a_paste_fills_cells_from_the_cursor(cx: &mut TestAppContext) {
cx.update(|cx| {
Theme::init(cx);
crate::forms::bind_keys(cx);
});
let heard = Rc::new(RefCell::new(Vec::new()));
let seen = heard.clone();
let (_, cx) = cx.add_window_view(|_, _| Grid(seen));
settle(cx);
cx.simulate_click(point(px(48.0), px(42.0)), Modifiers::none());
settle(cx);
cx.update(|_, cx| cx.write_to_clipboard(ClipboardItem::new_string("x\ty\nz\tw".into())));
cx.simulate_keystrokes("cmd-v");
settle(cx);
let cells = |row, col, text: &str| (row, col, text.to_string());
assert_eq!(
*heard.borrow(),
[
cells(0, 0, "x"),
cells(0, 1, "y"),
cells(1, 0, "z"),
cells(1, 1, "w")
]
);
}
+1
View File
@@ -9,6 +9,7 @@ use gpui::{
Styled, TestAppContext, VisualTestContext, Window, div, point, px,
};
mod clipboard;
mod columns;
use super::{Column, DataTable, FilterBuilder, FilterRule, Row};