Transform Again on a Copy (Cmd+Alt+Shift+T): step and repeat (part of #352) (#474)

The hidden shortcut for step-and-repeat was missing. A new command,
`edit.transform.againCopy` (no menu item, Cmd+Alt+Shift+T), duplicates
the active layer and repeats the last transform on the copy, as one
history step labelled "Transform Again", so repeated presses lay out a
row (or a ring) of copies one transform apart. The transform is worked
out before anything changes (`transform_again_params`, now shared with
Edit › Transform › Again), so nothing to repeat leaves no copy; a copy
that can't be transformed (position locked) is taken back with nothing
left to redo (`History::clear_redo`).

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BFlatandClaude Opus 5.5 authored and GitHub committed 2026-10-07 09:55:50 +07:00
1 parent f49b5a4853
commit f697e43ef7
8 files changed
+87 -1

No files matched your search

+76 -1
View File
@@ -357,6 +357,38 @@ fn toggle_last_state(s: &mut Session) -> Result<Value> {
/// Edit › Transform › Again: replay the last `edit.transform` on the active layer.
fn transform_again(s: &mut Session) -> Result<Value> {
let p = transform_again_params(s)?;
s.execute("edit.transform", p)
}
/// Transform Again on a copy (⌥⇧⌘T, no menu item): duplicates the active layer and repeats the
/// last transform on the copy, as one history step, so pressing it again steps and repeats
/// (#352). The transform is worked out before anything changes, so a refusal leaves no copy.
fn transform_again_copy(s: &mut Session) -> Result<Value> {
let p = transform_again_params(s)?;
let id = active_id(s)?;
s.execute("layer.duplicate", json!({"layer": id.0}))?;
match s.execute("edit.transform", p) {
Ok(r) => {
let st = s.active_mut().ok_or(EngineError::NoDocument)?;
st.history.purge_last();
st.history.set_current_label("Transform Again");
Ok(r)
}
Err(e) => {
// The copy (e.g. of a layer whose position is locked) couldn't be transformed: take
// it back, leaving nothing to redo.
s.undo();
if let Some(st) = s.active_mut() {
st.history.clear_redo();
}
Err(e)
}
}
}
/// The `edit.transform` params that repeat the last transform on the active layer.
fn transform_again_params(s: &Session) -> Result<Value> {
let (_, last) =
s.journal.iter().rev().find(|(id, _)| id == "edit.transform").cloned().ok_or(EngineError::Other("there is no transform to repeat".into()))?;
let (rect, quad) = (last.get("rect").cloned(), last.get("quad").cloned());
@@ -391,7 +423,7 @@ fn transform_again(s: &mut Session) -> Result<Value> {
(_, _, Some(m)) => p["matrix"] = m,
_ => return Err(EngineError::Other("the last transform can't be repeated".into())),
}
s.execute("edit.transform", p)
Ok(p)
}
/// View › New Guide / guide moves (undoable, like Photoshop's "New Guide"/"Move Guide" states).
@@ -470,6 +502,15 @@ pub fn specs() -> Vec<CommandSpec> {
spec!("image.autoColor", "Auto Color", &["Image"], Some("Cmd+Shift+B"), "{}", has_pixels, |s, _| auto_adjust(s, "color")),
spec!("edit.toggleLastState", "Toggle Last State", &["Edit"], Some("Cmd+Alt+Z"), "{}", has_doc, |s, _| toggle_last_state(s)),
spec!("edit.transform.again", "Again", &["Edit", "Transform"], Some("Cmd+Shift+T"), "{}", has_doc, |s, _| transform_again(s)),
spec!(
"edit.transform.againCopy",
"Transform Again on a Copy",
&[],
Some("Cmd+Alt+Shift+T"),
"{} (duplicates the active layer and repeats the last transform on the copy: step and repeat)",
has_doc,
|s, _| transform_again_copy(s)
),
spec!("view.newGuide", "New Guide…", &["View"], None, r##"{"orientation":"horizontal|vertical","position":px}"##, has_doc, |s, p| guide_cmd(
s, p, "new"
)),
@@ -698,6 +739,40 @@ mod tests {
}
}
/// #352: ⌥⇧⌘T steps and repeats: each press adds a copy one transform further on, and each
/// is one undo step.
#[test]
fn transform_again_on_a_copy_steps_and_repeats() {
let mut s = session();
assert!(s.execute("edit.transform.againCopy", json!({})).is_err(), "nothing to repeat yet");
assert_eq!(s.active().unwrap().doc.layers.len(), 2, "a refusal leaves no copy");
s.execute("edit.transform", json!({"matrix": [1, 0, 0, 1, 10, 0]})).unwrap();
let steps = s.active().unwrap().history.past_len();
for (i, x) in [30, 40].into_iter().enumerate() {
s.execute("edit.transform.againCopy", json!({})).unwrap();
let d = &s.active().unwrap().doc;
assert_eq!(d.layers.len(), 3 + i);
assert_eq!(active_bounds(&s), Rect::new(x, 10, x + 40, 30), "the copy moved one step further");
assert_eq!(s.active().unwrap().history.past_len(), steps + 1 + i, "one history step per press");
}
assert_eq!(s.active().unwrap().history.undo_label(), Some("Transform Again"));
// The original and the first copy stay where they were.
let d = &s.active().unwrap().doc;
let b = |i: usize| d.layers[i].surface().unwrap().content_bounds();
assert_eq!((b(1), b(2)), (Rect::new(20, 10, 60, 30), Rect::new(30, 10, 70, 30)));
// Undo removes the copy and its move together.
s.undo();
assert_eq!(s.active().unwrap().doc.layers.len(), 3);
assert_eq!(active_bounds(&s), Rect::new(30, 10, 70, 30));
// A copy that can't move (position locked) is taken back.
let id = s.active().unwrap().active_layer.unwrap();
s.execute("layer.setProps", json!({"layer": id.0, "locks": {"position": true}})).unwrap();
let layers = s.active().unwrap().doc.layers.len();
assert!(s.execute("edit.transform.againCopy", json!({})).unwrap_err().to_string().contains("locked"));
assert_eq!(s.active().unwrap().doc.layers.len(), layers);
assert!(!s.active().unwrap().history.can_redo(), "nothing to redo");
}
#[test]
fn toggle_last_state_and_transform_again() {
let mut s = session();
+5
View File
@@ -111,6 +111,11 @@ impl History {
self.undo.pop_back().is_some()
}
/// Forget the redo states, e.g. after undoing half of a compound step that failed.
pub fn clear_redo(&mut self) {
self.redo.clear();
}
pub fn clear(&mut self) {
self.undo.clear();
self.redo.clear();
+1
View File
@@ -110,6 +110,7 @@
Free Transform Volná transformace
Transform Transformace
Again Opakovat
Transform Again on a Copy Duplikovat a opakovat transformaci
Scale Měřítko
Rotate Otočit
Skew Zkosit
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -102,6 +102,7 @@
Free Transform Transformación libre
Transform Transformar
Again Repetir
Transform Again on a Copy Duplicar y repetir la transformación
Scale Escalar
Rotate Rotar
Skew Sesgar
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -106,6 +106,7 @@
Free Transform 自由変形
Transform 変形
Again もう一度
Transform Again on a Copy 複製してもう一度変形
Scale 拡大・縮小
Rotate 回転
Skew 斜体
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1679,6 +1679,7 @@
90° Counter Clockwise 90° против часовой стрелке
AI Integrations… Интеграции ИИ…
Again Снова
Transform Again on a Copy Дублировать и снова трансформировать
Anamorphic 2:1 (2) Анаморф 2:1 (2)
Arbitrary… Другой угол…
Artboard Guides Направляющие монтажной области
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -101,6 +101,7 @@
Free Transform 自由变换
Transform 变换
Again 再次变换
Transform Again on a Copy 复制并再次变换
Scale 缩放
Rotate 旋转
Skew 斜切
1 # Simplified Chinese (zh-hans) catalog. UTF-8, TAB-separated columns:
101
102
103
104
105
106
107
+1
View File
@@ -110,6 +110,7 @@
Free Transform 任意變形
Transform 變形
Again 再次
Transform Again on a Copy 複製並再次變形
Scale 縮放
Rotate 旋轉
Skew 傾斜
Can't render this file because it contains an unexpected character in line 6 and column 47.