ElyTable: a sheet starts at the left, even before its geometry arrives (T-03)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 10:16:11 -04:00
1 parent ecf977364b
commit a6d8a1de43
8 files changed
+43 -10

No files matched your search

+13 -4
View File
@@ -73,9 +73,16 @@ pub struct Doc {
id: u64,
/// The document's revision when this handle was taken.
pub(crate) rev: u64,
/// LOK_DOCTYPE: 0 text, 1 spreadsheet, 2 presentation.
kind: u64,
}
impl Doc {
/// Whether this is a spreadsheet.
pub fn is_sheet(&self) -> bool {
self.kind == 1
}
/// Whether this handle saw a later state than `other`.
pub fn newer_than(&self, other: &Doc) -> bool {
self.rev > other.rev
@@ -217,9 +224,10 @@ impl Worker {
pack.u64(at(COLUMNS.iter().position(|c| c == column)))
});
let payload = self.request(tag::IMPORT, &pack.bytes())?;
let id = Unpack::new(&payload).u64()?;
let mut reply = Unpack::new(&payload);
let (id, kind) = (reply.u64()?, reply.u64()?);
self.feed.opened(id);
Ok(Doc { worker: self.session, id, rev: 0 })
Ok(Doc { worker: self.session, id, rev: 0, kind })
}
/// Loads `url` with its password; a locked one is PermissionDenied.
@@ -232,9 +240,10 @@ impl Worker {
error
}
})?;
let id = Unpack::new(&payload).u64()?;
let mut reply = Unpack::new(&payload);
let (id, kind) = (reply.u64()?, reply.u64()?);
self.feed.opened(id);
Ok(Doc { worker: self.session, id, rev: 0 })
Ok(Doc { worker: self.session, id, rev: 0, kind })
}
/// Runs a macro by its URL (LOK-11 probe).
+3 -3
View File
@@ -181,17 +181,17 @@ mod tests {
};
feed.push(1, first);
feed.push(1, second);
let batch = feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 0, 0).expect("a batch");
let batch = feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 0, 0).expect("a batch");
assert_eq!((batch.seq, batch.all, batch.rects.len()), (2, true, 1));
assert_eq!(
batch.states,
[("b".to_string(), "1".to_string()), ("a".into(), "2".into())]
);
let idle = feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 2, 0).expect("the snapshot");
let idle = feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 2, 0).expect("the snapshot");
assert!(idle.rects.is_empty() && idle.states.is_empty() && idle.seq == 2);
feed.closed(1);
assert!(
feed.wait(&Doc { worker: 0, id: 1, rev: 0 }, 2, 0).is_err(),
feed.wait(&Doc { worker: 0, id: 1, rev: 0, kind: 0 }, 2, 0).is_err(),
"a closed document"
);
}
+4
View File
@@ -251,6 +251,10 @@ impl LokView {
/// Room beside a narrow document, which sits centred.
pub(super) fn slack(&self) -> (f32, f32) {
// A sheet's grid grows with the view; it starts left.
if self.doc.is_sheet() {
return (0.0, 0.0);
}
let extent = self.extent();
let slack = |view: f32, doc: i32| (view - self.geom.px_of(doc)).max(0.0) / 2.0;
// A fitted page sits centred both ways.
+5
View File
@@ -186,7 +186,12 @@ fn a_sheet_brings_far_cut_and_frozen_cells_into_view() {
let (view, worker) = live_view_of(app, &install, "short.fods", SHORT_ROWS);
let json = worker.lock().expect("the worker lock").values(&view.read(app).doc, crate::sheet::GEOMETRY).expect("geometry");
view.update(app, |view, cx| {
let wide = Bounds { origin: point(px(0.0), px(0.0)), size: size(px(6000.0), px(200.0)) };
view.prepare(wide);
assert_eq!(view.spare, (0.0, 0.0), "before its geometry a sheet starts left");
view.set_geometry(crate::sheet::geometry(&json).expect("parsed"), cx);
view.prepare(wide);
assert_eq!(view.spare, (0.0, 0.0), "and stays left after it");
view.viewport = (800.0, 200.0);
let (width, height) = (view.geom.twips_of(view.viewport.0), view.geom.twips_of(view.viewport.1));
let shows = |view: &LokView, rect: crate::Rect| {
+8 -2
View File
@@ -187,8 +187,8 @@ fn answer(lok: &Lok, tag: u8, id: u64, payload: &[u8]) {
.str()
.and_then(|url| Ok((url, unpack.str()?)))
.and_then(|(url, password)| load(lok, &url, password, ""))
.map(|id| Pack::new().u64(id).bytes()),
tag::IMPORT => text::import(lok, unpack).map(|id| Pack::new().u64(id).bytes()),
.and_then(loaded),
tag::IMPORT => text::import(lok, unpack).and_then(loaded),
tag::EXPORT_TEXT => text::export(unpack).map(|()| Vec::new()),
tag::DOC_SIZE => unpack
.u64()
@@ -339,6 +339,12 @@ fn load(lok: &Lok, url: &str, password: String, filter: &str) -> io::Result<u64>
Ok(id)
}
/// The reply to a load: the number and LOK_DOCTYPE.
fn loaded(id: u64) -> io::Result<Vec<u8>> {
let kind = with_doc(id, |doc| doc.kind())?;
Ok(Pack::new().u64(id).u64(kind as u64).bytes())
}
/// Stops watching and frees document `id`.
fn close(id: u64) {
let mut docs = docs().lock().expect("the docs lock");