From dbd7a90e23f4a4e8bc0cfbb56691ebcf43dcbebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 14 Feb 2016 01:45:16 +0100 Subject: [PATCH] Better detect code that requires a tool object. Closes #967 --- src/core/PaperScript.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 7950a647..a1c7df0f 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -386,11 +386,10 @@ Base.exports.PaperScript = (function() { // Set currently active scope. paper = scope; var view = scope.getView(), - // Only create a tool object if something resembling a tool handler - // definition is contained in the code. - tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code) - ? new Tool() - : null, + // Only create a tool if the tool object is accessed or something + // resembling a global tool handler is contained in the code. + tool = /\btool\.\w+|\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/ + .test(code) ? new Tool() : null, toolHandlers = tool ? tool._events : [], // Compile a list of all handlers that can be defined globally // inside the PaperScript. These are passed on to the function as