Skip to content

Commit

Permalink
core: new utility functions for block traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Sep 21, 2023
1 parent 4985e1d commit 5505b26
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/Sandblocks-Core/SBBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ SBBlock >> addBlock: aBlock [
(self insertCommandRequest: aBlock near: nil before: false) do
]

{ #category : #hierarchy }
SBBlock >> allBlocksBreadthFirst [

^ Array streamContents: [:s | self allBlocksBreadthFirstDo: [:b | s nextPut: b]]
]

{ #category : #hierarchy }
SBBlock >> allBlocksBreadthFirstDo: aClosure [

(aClosure value: self) == true ifTrue: [^ true].
self childSandblocksDo: [:b | b allBlocksBreadthFirstDo: aClosure]
]

{ #category : #'as yet unclassified' }
SBBlock >> allBlocksDetect: aBlock [

Expand Down Expand Up @@ -1315,6 +1328,14 @@ SBBlock >> hasMultiSelection [
^ self sandblockEditor cursor cursorPosition isKindOf: SBCursorMultiSelect
]

{ #category : #'as yet unclassified' }
SBBlock >> hasParent: aBlock [

self parentSandblock ifNil: [^ false].
self parentSandblock = aBlock ifTrue: [^ true].
^ self parentSandblock hasParent: aBlock
]

{ #category : #'actions tests' }
SBBlock >> hasSuggestions [

Expand Down Expand Up @@ -3141,6 +3162,18 @@ SBBlock >> wasSelectedFromCursor: aCursorPosition [

]

{ #category : #'as yet unclassified' }
SBBlock >> with: anotherBlock parentsDo: aClosure [

| currentSelf currentOther |
currentSelf := self.
currentOther := anotherBlock.

[aClosure value: currentSelf value: currentOther] doWhileTrue: [
currentSelf := currentSelf parentSandblock.
(currentOther := currentOther parentSandblock) notNil]
]

{ #category : #decorators }
SBBlock >> withDecorator: aClass do: aBlock [

Expand Down

0 comments on commit 5505b26

Please sign in to comment.