From e0a0cd58d534763552d9ebc8ded95476d1eea422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 13 Apr 2016 15:21:35 -0700 Subject: [PATCH] PaperScript: Improve tool detection code. And implement Multiple Tools example. --- examples/Tools/MultipleTools.html | 44 +++++++++++++++++++++++++++++++ src/core/PaperScript.js | 6 +++-- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 examples/Tools/MultipleTools.html diff --git a/examples/Tools/MultipleTools.html b/examples/Tools/MultipleTools.html new file mode 100644 index 00000000..d2c21ee6 --- /dev/null +++ b/examples/Tools/MultipleTools.html @@ -0,0 +1,44 @@ + + + + +Mulitple Tools + + + + + + Lines + Clouds + + + diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 0d0b569b..efb8f52b 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -387,9 +387,11 @@ Base.exports.PaperScript = (function() { paper = scope; var view = scope.getView(), // Only create a tool if the tool object is accessed or something - // resembling a global tool handler is contained in the code. + // resembling a global tool handler is contained in the code, but + // no tool objects are actually created. tool = /\btool\.\w+|\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/ - .test(code) ? new Tool() : null, + .test(code) && !/\bnew\s+Tool\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