mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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:
1 parent
f49b5a4853
commit
f697e43ef7
8 files changed
+87
-1
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
@@ -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.
|
@@ -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.
|
@@ -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.
|
@@ -101,6 +101,7 @@
|
||||
Free Transform 自由变换
|
||||
Transform 变换
|
||||
Again 再次变换
|
||||
Transform Again on a Copy 复制并再次变换
|
||||
Scale 缩放
|
||||
Rotate 旋转
|
||||
Skew 斜切
|
||||
|
||||
|
@@ -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.
|
Reference in new issue
Block a user