Skip to content

Commit

Permalink
Resolves wrapper code in watches when variants or watches are nested
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Jan 5, 2024
1 parent 3ae5ff5 commit 0fe9f32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down

0 comments on commit 0fe9f32

Please sign in to comment.