From 0fe9f32dd5d265a4ab5bfdaea60e0f73dea50479 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Sat, 6 Jan 2024 00:20:19 +0100 Subject: [PATCH] Resolves wrapper code in watches when variants or watches are nested --- .../SBExampleWatch.class.st | 23 +++++++++++++++++++ .../SBInactiveExampleWatch.class.st | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index 30810cbe..d0a1ddab 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -127,6 +127,29 @@ SBExampleWatch >> asInactiveCopy [ ^ SBInactiveExampleWatch newFromWatch: self ] +{ #category : #accessing } +SBExampleWatch >> cleanedExpression [ + + "ignores code wrappings for watches and variants" + | copy nextToRemove newOwner | + copy := self expression veryDeepCopy. + newOwner := SBStBlockBody new. + newOwner appendStatements: {copy}. + [copy allBlocksDo: [:subBlock | + (subBlock isVariant or: [subBlock isWatch]) ifTrue: [nextToRemove := subBlock]]. nextToRemove] + whileNotNil: [ + nextToRemove isWatch ifTrue: [nextToRemove replaceBy: nextToRemove cleanedExpression]. + nextToRemove isVariant ifTrue:[ + "when users play around with putting multiple statements in a nested variant inside a watch, + even though watches are only possible on single expressions, + we are ok with them losing information here" + nextToRemove replaceBy: (nextToRemove statementsFor: nextToRemove active) first]. + nextToRemove = copy ifTrue: [^newOwner]. + nextToRemove := nil]. + + ^ newOwner statements first +] + { #category : #'colors and color policies' } SBExampleWatch >> color [ diff --git a/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st index 91c075be..e073ecfb 100644 --- a/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st @@ -12,7 +12,7 @@ SBInactiveExampleWatch class >> newFromWatch: anActiveWatch [ ^ (anActiveWatch veryDeepCopy) primitiveChangeClassTo: self basicNew; - expression: (SBTextBubble new contents: anActiveWatch expression sourceString); + expression: (SBTextBubble new contents: anActiveWatch cleanedExpression sourceString); saveObjectsActivePermutations; yourself ]