From 11d67037e7bf893c6ae52ec127c5c8f197a799a8 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Thu, 2 Oct 2025 15:11:07 +0200 Subject: [PATCH] Make PenpotUtils.findShape search across all pages (i.e. globally) --- penpot-plugin/src/PenpotUtils.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/penpot-plugin/src/PenpotUtils.ts b/penpot-plugin/src/PenpotUtils.ts index 35af48a..d2a9070 100644 --- a/penpot-plugin/src/PenpotUtils.ts +++ b/penpot-plugin/src/PenpotUtils.ts @@ -58,9 +58,9 @@ export class PenpotUtils { * Finds the first shape that matches the given predicate in the given shape tree. * * @param predicate - A function that takes a shape and returns true if it matches the criteria - * @param root - The root shape to start the search from (defaults to penpot.root) + * @param root - The root shape to start the search from (if null, searches all pages) */ - public static findShape(predicate: (shape: Shape) => boolean, root: Shape | null = penpot.root): Shape | null { + public static findShape(predicate: (shape: Shape) => boolean, root: Shape | null = null): Shape | null { let find = function (shape: Shape | null): Shape | null { if (!shape) { return null; @@ -79,7 +79,20 @@ export class PenpotUtils { return null; }; - return find(root); + if (root === null) { + const pages = penpot.currentFile?.pages; + if (pages) { + for (let page of pages) { + let result = find(page.root); + if (result) { + return result; + } + } + } + return null; + } else { + return find(root); + } } /**