Merge main into fix/open-dwg-files

This commit is contained in:
dotCooCoo committed 2026-12-03 23:07:43 -08:00
commit 216dfb83ec
4 files changed
+77 -1

No files matched your search

+3
View File
@@ -218,6 +218,9 @@ mod tests {
fn panel(id: &'static str) -> Panel {
SHOWN.with(|s| *s.borrow_mut() = id);
let mut app = VectorcraftApp::new(Session::new(), Default::default());
// The scan of the installed fonts, which the app starts, changes the fonts' generation when it ends, and the
// bodies' inputs hold that generation: wait for it, or an idle frame that it ends in runs the body.
vectorcraft_text::FontDb::global().family_list();
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
let mut panel = Panel::new(app, draw);
+4 -1
View File
@@ -477,7 +477,10 @@ fn build_catalog(app: &VectorcraftApp, listed: &Listed, plays: &[(String, craft:
Ok(catalog) => {
// While a text field has the keys no shortcut runs, as in production; the text-editing chords still edit it,
// and the Type tool's commands run while it types.
let catalog = catalog.typing_rule(TypingRule::AllWait);
// The document canvas also defaults to Cmd+0, but its Fit on Screen stops at actual size.
// Leave that chord to VectorCraft's Fit Artboard in Window.
let fit_on_screen = CommandRef::from(craft::ui::canvas::ViewCommands::FitOnScreen);
let catalog = catalog.typing_rule(TypingRule::AllWait).replace_defaults(fit_on_screen.id, Vec::new());
let catalog = linked_keys.into_iter().fold(catalog, |catalog, (id, keys)| catalog.replace_defaults(id, keys));
let catalog = UNROUTED.iter().fold(catalog, |catalog, id| catalog.replace_defaults(id.as_str(), Vec::new()));
Some(type_keys.into_iter().fold(catalog, |catalog, (id, keys)| catalog.replace_defaults(id, keys)))
+27
View File
@@ -80,6 +80,33 @@ fn idle(app: &mut VectorcraftApp, ctx: &egui::Context, n: usize) {
}
}
/// A focused document canvas must use the app's artboard fit, whose zoom may exceed 100%.
#[test]
fn command_zero_fits_the_active_artboard_when_the_canvas_has_focus() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 120, "height": 80, "artboards": 2})).unwrap();
app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": false})).unwrap();
let ctx = ready(&mut app);
app.view_mut().unwrap().artboard = 1;
app.run("view.fitArtboard", json!({})).unwrap();
idle(&mut app, &ctx, 12);
let fitted = app.view().unwrap();
let (zoom, center) = (fitted.zoom, fitted.center);
assert!(zoom > 1.0, "this artboard has room to grow past actual size: {zoom}");
app.run("view.setZoom", json!({"zoom": 50})).unwrap();
idle(&mut app, &ctx, 12);
focus_canvas(&mut app, &ctx);
assert!(app.view().unwrap().zoom < 1.0);
key_frame(&mut app, &ctx, tap(Key::Num0, cmd()));
idle(&mut app, &ctx, 12);
let fitted = app.view().unwrap();
assert!((fitted.zoom - zoom).abs() < 1e-6, "shortcut zoom {} should match the menu fit {zoom}", fitted.zoom);
assert_eq!(fitted.center, center, "fit the active artboard, not the whole document");
}
/// An app with a 200 × 200 document whose window has drawn its first frame, which builds the keymap the shortcut
/// commands edit.
fn new_app() -> VectorcraftApp {
+43
View File
@@ -4245,6 +4245,49 @@ change anything outside the documents: `script.*` except `script.check`, `plugin
an error. With Data Recovery off for complex documents, a run in the web build does not start while a complex document
has unsaved changes.
#### Create a numbered grid
Open the drawing, save the code below as `Number Grid.jsx`, then run it with **File › Scripts › Other Script…**.
Change the first number, count, columns and spacing before running it. Positions and spacing are in document
points. `left` and `top` set the baseline origin of the first label, and numbers advance across each row.
Every label stays editable with the Type tool. One Undo removes the entire grid.
```javascript
var firstNumber = 1;
var count = 31;
var columns = 7;
var left = 36;
var top = 54;
var columnSpacing = 42;
var rowSpacing = 32;
var size = 16;
if (count < 1 || count > 1000 || count !== Math.floor(count)) {
throw new Error("Count must be a whole number from 1 to 1000.");
}
if (!isFinite(columns) || columns < 1 || columns !== Math.floor(columns)) {
throw new Error("Columns must be a positive whole number.");
}
var maxInteger = 9007199254740991;
var lastNumber = firstNumber + (count - 1);
if (firstNumber !== Math.floor(firstNumber) ||
Math.abs(firstNumber) > maxInteger || Math.abs(lastNumber) > maxInteger) {
throw new Error("The first and last label number must be safe integers.");
}
for (var i = 0; i < count; i++) {
vc.run("text.create", {
x: left + (i % columns) * columnSpacing,
y: top + Math.floor(i / columns) * rowSpacing,
text: String(firstNumber + i),
size: size
});
}
```
This example creates up to 1,000 labels in one run. Make more room between larger labels by increasing
`columnSpacing`.
### Script engines
A named engine (`#targetengine`) keeps its globals and functions between the runs that name it, until it is dropped