R5.6: ElyShow right-click menus, PowerPoint-style; Impress table borders drag; R3 PASS

The canvas offers Ely's menu by target: slide (layouts, comment), text
(bullets, numbering, comment), shape or text box, picture (replace,
crop), table (insert, delete, merge), each item gated by the kernel's
state for its own command. Impress's table borders read as text and
drag through R5.3's path; patch 0047 reports every edge's bounds and
makes the left edge drag. A line past its bound never moves against
the drag, so a still press sends nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-14 14:26:27 -04:00
1 parent 411d32b97e
commit 35a7bbb904
21 files changed
+920 -24

No files matched your search

+74 -8
View File
@@ -1,4 +1,4 @@
//! The cursor's table borders, as Writer reports them (DOC-07).
//! A table's borders, as Writer and Impress report them (DOC-07).
use std::io;
@@ -15,6 +15,8 @@ pub struct Lines {
pub right: i32,
pub offset: i32,
pub inner: Vec<Line>,
/// Bounds of the first and last lines, when sent.
pub ends: Option<[(i32, i32); 2]>,
}
/// An inner line and the kernel's bounds for it.
@@ -41,22 +43,47 @@ pub fn read(text: &str) -> Result<Option<Table>, String> {
if object.is_empty() {
return Ok(None);
}
let int = |value: Option<&Value>| i32::try_from(value?.as_i64()?).ok();
// Impress writes every value as text (boost's property tree).
let int = |value: Option<&Value>| match value? {
Value::Number(number) => i32::try_from(number.as_i64()?).ok(),
Value::String(text) => text.parse().ok(),
_ => None,
};
let flag = |value: Option<&Value>| match value? {
Value::Bool(on) => Some(*on),
Value::String(text) => text.parse().ok(),
_ => None,
};
let lines = |key: &str| -> Option<Lines> {
let axis = object.get(key)?;
let inner = axis.get("entries")?.as_array()?.iter().map(|entry| {
// Boost writes an empty list as an empty string.
let entries = match axis.get("entries")? {
Value::Array(entries) => entries.as_slice(),
Value::String(text) if text.is_empty() => &[],
_ => return None,
};
let inner = entries.iter().map(|entry| {
Some(Line {
position: int(entry.get("position"))?,
min: int(entry.get("min"))?,
max: int(entry.get("max"))?,
hidden: entry.get("hidden")?.as_bool()?,
hidden: flag(entry.get("hidden"))?,
})
});
let bound = |key: &str| int(axis.get(key));
let ends = match ["leftMin", "leftMax", "rightMin", "rightMax"].map(|key| axis.get(key).is_some()) {
[false, false, false, false] => None,
[true, true, true, true] => {
Some([(bound("leftMin")?, bound("leftMax")?), (bound("rightMin")?, bound("rightMax")?)])
}
_ => return None,
};
Some(Lines {
left: int(axis.get("left"))?,
right: int(axis.get("right"))?,
offset: int(axis.get("tableOffset"))?,
inner: inner.collect::<Option<_>>()?,
ends,
})
};
let columns = lines("columns").ok_or_else(fault)?;
@@ -75,6 +102,10 @@ impl Table {
.i64(axis.right.into())
.i64(axis.offset.into())
.u64(axis.inner.len() as u64);
let pack = match axis.ends {
None => pack.u64(0),
Some(ends) => ends.iter().fold(pack.u64(1), |pack, &(low, high)| pack.i64(low.into()).i64(high.into())),
};
axis.inner.iter().fold(pack, |pack, line| {
pack.i64(line.position.into())
.i64(line.min.into())
@@ -91,14 +122,22 @@ impl Table {
let mut lines = || -> io::Result<Lines> {
let mut int = || i32::try_from(unpack.i64()?).map_err(io::Error::other);
let (left, right, offset) = (int()?, int()?, int()?);
let inner = (0..unpack.u64()?)
let count = unpack.u64()?;
let ends = match unpack.u64()? {
0 => None,
_ => {
let mut int = || i32::try_from(unpack.i64()?).map_err(io::Error::other);
Some([(int()?, int()?), (int()?, int()?)])
}
};
let inner = (0..count)
.map(|_| {
let mut int = || i32::try_from(unpack.i64()?).map_err(io::Error::other);
let (position, min, max) = (int()?, int()?, int()?);
Ok(Line { position, min, max, hidden: unpack.u64()? != 0 })
})
.collect::<io::Result<_>>()?;
Ok(Lines { left, right, offset, inner })
Ok(Lines { left, right, offset, inner, ends })
};
let columns = lines()?;
let rows = lines()?;
@@ -112,14 +151,41 @@ mod tests {
const SEEN: &str = r#"{ "columns": { "left": 0, "right": 9638, "tableOffset": 1135, "entries": [ { "position": 4819, "min": 300, "max": 9338, "hidden": false } ] }, "rows": { "left": 0, "right": 552, "tableOffset": 1418, "entries": [ { "position": 276, "min": 100, "max": 552, "hidden": false } ] } }"#;
/// As Impress sent it for a new 2x2 table.
const IMPRESS: &str = r#"{ "columns": { "tableOffset": "3929", "left": "0", "right": "7993", "entries": [ { "position": "3996", "min": "340", "max": "7653", "hidden": "false" } ] }, "rows": { "tableOffset": "4340", "left": "0", "right": "1091", "entries": [ { "position": "545", "min": "340", "max": "152183880", "hidden": "false" } ] }, "rectangle": { "x": "3940", "y": "4351", "width": "7993", "height": "1091" } }"#;
#[test]
fn impress_writes_numbers_as_text() {
let table = read(IMPRESS).expect("readable").expect("a table");
assert_eq!(table.columns.offset, 3929);
assert_eq!(table.columns.inner, [Line { position: 3996, min: 340, max: 7653, hidden: false }]);
assert_eq!(table.rows.right, 1091);
assert!(read(&IMPRESS.replace("\"false\"", "\"no\"")).is_err(), "a flag is true or false");
assert_eq!(table.rows.ends, None, "an unpatched kernel sends no ends");
}
/// One row, as Impress sends it with patch 0047.
const ONE_ROW: &str = r#"{ "columns": { "tableOffset": "3929", "left": "0", "right": "7993", "leftMin": "-152183880", "leftMax": "7823", "rightMin": "170", "rightMax": "152183880", "entries": "" }, "rows": { "tableOffset": "4340", "left": "0", "right": "545", "leftMin": "-152183880", "leftMax": "28", "rightMin": "517", "rightMax": "152183880", "entries": "" } }"#;
#[test]
fn one_line_has_no_inner_lines_and_its_ends_cross_the_wire() {
let table = read(ONE_ROW).expect("readable").expect("a table");
assert!(table.columns.inner.is_empty() && table.rows.inner.is_empty());
assert_eq!(table.rows.ends, Some([(-152_183_880, 28), (517, 152_183_880)]));
assert!(read(&ONE_ROW.replace("\"entries\": \"\"", "\"entries\": \"x\"")).is_err(), "text is no list");
assert!(read(&ONE_ROW.replace("\"leftMin\": \"-152183880\", ", "")).is_err(), "ends come in fours");
let bytes = Table::pack(Some(&table), Pack::new()).bytes();
assert_eq!(Table::unpack(&mut Unpack::new(&bytes)).expect("unpacks"), Some(table));
}
#[test]
fn a_table_reads_and_crosses_the_wire() {
assert_eq!(read("{ }"), Ok(None), "no table");
let table = read(SEEN).expect("readable").expect("a table");
assert_eq!(table.columns.offset, 1135);
assert_eq!(table.rows.inner[0].position, 276);
let text = SEEN.replace("\"left\": 0,", "\"left\": \"0\",");
assert!(read(&text).is_err(), "a number as text is a fault");
let text = SEEN.replace("\"left\": 0,", "\"left\": \"zero\",");
assert!(read(&text).is_err(), "a word is no number");
assert!(read("[]").is_err());
let bytes = Table::pack(Some(&table), Pack::new()).bytes();
let back = Table::unpack(&mut Unpack::new(&bytes)).expect("unpacks");