From efdaa06fd260c32545364dac795d2f2e402cd3b4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 21:10:26 -0800 Subject: [PATCH] Scripts: reflect reports matrix defaults; copy notes keep the recording limit - app.reflect now reports the defaults of the matrix functions' number arguments: 0 for deltaX, deltaY and angle, and 100 for scaleX, in the get and concatenate variants. scaleY has no fixed default, since a left-out vertical scale is the horizontal one; its description says so. - When a script's commands take a recording past its limit and the script also copied, the notes of the Copy's formats no longer replace the limit message in the status bar. The limit is named only once, so the message is kept while it shows. The same applies to a script run that automation takes to its end at once. --- crates/engine/src/script/dom/matrix.rs | 20 ++++++++++++- crates/engine/src/tests/script_dom_prefs.rs | 20 +++++++++++++ .../ui-egui/src/panels/actions/recording.rs | 2 ++ .../src/panels/actions/tests_limits.rs | 29 +++++++++++++++++++ crates/ui-egui/src/sysclip.rs | 11 ++++++- 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/script/dom/matrix.rs b/crates/engine/src/script/dom/matrix.rs index e9fd55e70b..0887168db8 100644 --- a/crates/engine/src/script/dom/matrix.rs +++ b/crates/engine/src/script/dom/matrix.rs @@ -19,7 +19,7 @@ //! - An argument that is not a finite number, or a matrix with a value that is not one, throws a //! `TypeError`; a result with a value too large for a number throws a `RangeError`. -use vectorcraft_js::{Data, HostError}; +use vectorcraft_js::{Data, HostError, MemberInfo}; use super::{Answer, Described, Host, Link, arg, method, named, num, returns, text}; @@ -54,6 +54,24 @@ pub(super) fn app_members(link: &Link) -> Vec { ("isEqualMatrix", method(l, is_equal), returns("boolean", &[("matrix", "Matrix"), ("secondMatrix", "Matrix")])), ("isSingularMatrix", method(l, is_singular), returns("boolean", &[("matrix", "Matrix")])), ]) + .into_iter() + .map(|(name, member, info)| (name, member, with_defaults(info))) + .collect() +} + +/// `info` with the defaults of its left-out number arguments, which `reflect` reports: 0 for a +/// translation and an angle, 100 for a horizontal scale. A left-out vertical scale is the +/// horizontal one, so it has no fixed default and its description says so. +fn with_defaults(mut info: MemberInfo) -> MemberInfo { + for a in &mut info.arguments { + match a.name.as_str() { + "deltaX" | "deltaY" | "angle" => a.default = Some(num(0.0)), + "scaleX" => a.default = Some(num(100.0)), + "scaleY" => a.description = Some("The vertical scale; when it is left out, the horizontal scale.".into()), + _ => {} + } + } + info } /// The record for `m`, or a `RangeError` when a value is not finite. diff --git a/crates/engine/src/tests/script_dom_prefs.rs b/crates/engine/src/tests/script_dom_prefs.rs index 5cb7acb4b2..624ff8a7f8 100644 --- a/crates/engine/src/tests/script_dom_prefs.rs +++ b/crates/engine/src/tests/script_dom_prefs.rs @@ -342,6 +342,26 @@ fn matrix_functions_give_new_records() { assert_eq!(r, vec![json!([c, sn, -sn, c])]); } +#[test] +fn reflect_reports_the_matrix_argument_defaults() { + let mut s = Session::new(); + let out = log( + &mut s, + "function d(f, a) { return String(app.reflect.find(f).arguments[a].defaultValue); }\ + vc.log([d('getScaleMatrix', 'scaleX'), d('concatenateScaleMatrix', 'scaleX'), d('getTranslationMatrix', 'deltaX'),\ + d('concatenateTranslationMatrix', 'deltaY'), d('getRotationMatrix', 'angle'), d('concatenateRotationMatrix', 'angle'),\ + d('getScaleMatrix', 'scaleY'), d('concatenateMatrix', 'matrix')]);\ + vc.log(app.reflect.find('getScaleMatrix').arguments.scaleY.description);", + ); + assert_eq!( + out, + vec![ + json!(["100", "100", "0", "0", "0", "0", "undefined", "undefined"]), + json!("The vertical scale; when it is left out, the horizontal scale."), + ] + ); +} + #[test] fn concatenation_applies_the_first_matrix_first() { let mut s = Session::new(); diff --git a/crates/ui-egui/src/panels/actions/recording.rs b/crates/ui-egui/src/panels/actions/recording.rs index bf0d4440f8..13ce1bf3bf 100644 --- a/crates/ui-egui/src/panels/actions/recording.rs +++ b/crates/ui-egui/src/panels/actions/recording.rs @@ -172,6 +172,8 @@ pub(crate) fn after_journaled_edit(app: &mut VectorcraftApp) -> bool { Ok(()) => false, Err(e) => { app.status(e); + // The limit is named once: the notes of the edit's Copy or Cut do not replace it. + app.clipboard_publishing.keep_status(&app.ui); true } } diff --git a/crates/ui-egui/src/panels/actions/tests_limits.rs b/crates/ui-egui/src/panels/actions/tests_limits.rs index a4b22246fd..5ecd1c718b 100644 --- a/crates/ui-egui/src/panels/actions/tests_limits.rs +++ b/crates/ui-egui/src/panels/actions/tests_limits.rs @@ -295,6 +295,35 @@ fn script_run_checks_recording_step_limit_on_completion() { } } +/// A script that copies type in a family that is not installed, whose Copy's formats therefore +/// have notes, and whose commands take a recording past 10,000 steps: the status bar keeps naming +/// the limit once the formats are written. Without the recording the notes show. +#[test] +fn a_scripts_copy_notes_do_not_replace_the_recording_limit() { + let steps = "the action already has 10,000 steps"; + let copy = "var t = vc.run('text.create', {x: 5, y: 20, text: 'Ab', font: 'Nonexistent Sans Probe'});\ + vc.run('select.set', {ids: [t.id]}); app.copy();"; + for frames in [false, true] { + for recording in [true, false] { + let services = crate::tests::sysclip::fake_clipboard_services(); + let app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), services)); + let (mut app, _) = three_moves_in(app); + if recording { + recording_with(&mut app, files::MAX_ACTION_STEPS - 1); + } + app.ui.status.clear(); + run_script(&mut app, copy, frames); + let _ = app.written_clipboard_text(); + let what = format!("frames {frames}, recording {recording}"); + if recording { + assert_eq!(app.ui.status, steps, "{what}: the limit stays in the status bar"); + } else { + assert!(app.ui.status.starts_with("Copied with "), "{what}: {}", app.ui.status); + } + } + } +} + /// A script whose commands give the recording's set a file larger than 8 MiB keeps its edit, /// the status bar names the limit as the run ends, and Stop Playing/Recording keeps the steps /// that fit in a set that Load Actions… reads. One that fills the file exactly names no limit. diff --git a/crates/ui-egui/src/sysclip.rs b/crates/ui-egui/src/sysclip.rs index 9371e118fd..8c54822d2f 100644 --- a/crates/ui-egui/src/sysclip.rs +++ b/crates/ui-egui/src/sysclip.rs @@ -94,6 +94,9 @@ pub(crate) struct Publishing { /// The status bar's message the latest Copy or Cut with notes left, with /// [`crate::state::UiState::status_sets`] then. notes_status: Option<(String, u64)>, + /// A message that no Copy or Cut's notes replace while the status bar shows it (a recording's + /// limit, which is named once), with [`crate::state::UiState::status_sets`] then. + kept: Option<(String, u64)>, } impl Publishing { @@ -118,7 +121,13 @@ impl Publishing { /// Does `ui`'s status bar still show the message the latest Copy or Cut left, with nothing /// setting the status since? fn shows_status(&self, ui: &crate::state::UiState) -> bool { - ui.status == self.status.0 && ui.status_sets == self.status.1 + let kept = self.kept.as_ref().is_some_and(|(s, sets)| ui.status == *s && ui.status_sets == *sets); + !kept && ui.status == self.status.0 && ui.status_sets == self.status.1 + } + + /// `ui`'s status bar message stays while it shows: no Copy or Cut's notes replace it. + pub(crate) fn keep_status(&mut self, ui: &crate::state::UiState) { + self.kept = Some((ui.status.clone(), ui.status_sets)); } /// Is the latest Copy or Cut one whose formats could not be written to `cb`, with nothing