Skip to content

Commit

Permalink
core: allow marking blocks as not selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Sep 22, 2023
1 parent 5db6f00 commit e9dcb06
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/Sandblocks-Core/Morph.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Morph >> copyBlock [
{ #category : #'*Sandblocks-Core' }
Morph >> cursorPositionsDo: aBlock [

self cursorPositionsDo: aBlock shallow: false
self cursorPositionsDo: [:pos | pos block selectable ifTrue: [aBlock value: pos]] shallow: false
]

{ #category : #'*Sandblocks-Core' }
Expand Down
24 changes: 19 additions & 5 deletions packages/Sandblocks-Core/SBBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,12 @@ SBBlock >> ensureVisible [

self isInWorld ifTrue: [ | show |
show := self fullBounds.
self allOwnersDo: [:o |
(o isKindOf: ScrollPane) ifTrue: [
o scrollToShow: show.
show := o fullBounds]].
"FIXME: for insert cursors, the block bounds are not relevant but this does not belong here (assumption of selection that is not in ensureVisible)"
self sandblockEditor cursor mode = #insert ifFalse: [
self allOwnersDo: [:o |
(o isKindOf: ScrollPane) ifTrue: [
o scrollToShow: show.
show := o fullBounds]]].

self sandblockEditor ifNotNil: [:e |
e scrollToShow: (e cursor cursorPosition block = self
Expand Down Expand Up @@ -1684,7 +1686,7 @@ SBBlock >> isScope [
{ #category : #testing }
SBBlock >> isSelectable [

^ true
^ self selectable
]

{ #category : #testing }
Expand Down Expand Up @@ -2662,6 +2664,18 @@ SBBlock >> selectToplevelTowards: aSideSymbol [
to: (opposite, 'Center') asSymbol) select
]

{ #category : #accessing }
SBBlock >> selectable [

^ self valueOfProperty: #selectable ifAbsent: true
]

{ #category : #accessing }
SBBlock >> selectable: aBoolean [

self allMorphsDo: [:m | m setProperty: #selectable toValue: aBoolean]
]

{ #category : #callbacks }
SBBlock >> selectedTextMorph: aMorph [

Expand Down
6 changes: 4 additions & 2 deletions packages/Sandblocks-Core/SBBlockCursor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ SBBlockCursor >> morphicLayerNumber [
{ #category : #api }
SBBlockCursor >> moveCursorClick: aBlock at: aPoint [

self cursorPosition: (self cursorForBlock: aBlock at: aPoint) explicitMove: true axis: #none
| cursor |
cursor := self cursorForBlock: aBlock at: aPoint.
cursor block selectable ifTrue: [self cursorPosition: cursor explicitMove: true axis: #none]
]

{ #category : #api }
Expand Down Expand Up @@ -568,7 +570,7 @@ SBBlockCursor >> select: aBlock [

aBlock
ifNil: [self cursorPosition: SBCursorNone new explicitMove: false axis: #none]
ifNotNil: [self cursorPosition: (self cursorForBlock: aBlock at: nil) explicitMove: false axis: #none]
ifNotNil: [aBlock selectable ifTrue: [self cursorPosition: (self cursorForBlock: aBlock at: nil) explicitMove: false axis: #none]]
]

{ #category : #api }
Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Core/SBCursorPosition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SBCursorPosition >> cursorPositionsIn: aContainer [
SBCursorPosition >> cursorPositionsIn: aContainer do: aBlock [
" enumerate all possible cursor positions recursively "

aContainer cursorPositionsDo: aBlock
aContainer cursorPositionsDo: [:pos | pos block selectable ifTrue: [aBlock value: pos]]
]

{ #category : #'as yet unclassified' }
Expand Down
7 changes: 4 additions & 3 deletions packages/Sandblocks-Core/SBEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1537,9 +1537,10 @@ SBEditor >> search [
{ #category : #selection }
SBEditor >> select: aBlock [

(aBlock notNil and: [aBlock isTextMorph and: [aBlock containingSandblock textMorphs includes: aBlock]]) ifTrue: [
^ self startInput: aBlock containingSandblock at: 9e8 replacingContents: false in: aBlock].

(aBlock isNil or: [aBlock isSandblock not or: [aBlock selectable]]) ifFalse: [^ self].

(aBlock notNil and: [aBlock isTextMorph and: [aBlock containingSandblock textMorphs includes: aBlock]]) ifTrue: [^ self startInput: aBlock containingSandblock at: 900000000 replacingContents: false in: aBlock].

self assert: (aBlock isNil or: [aBlock isSandblock]).
self cursor select: aBlock
]
Expand Down
5 changes: 3 additions & 2 deletions packages/Sandblocks-Core/SBHoverDecorator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ SBHoverDecorator >> position: aPoint [
c := self morph sandblockEditor cursor
cursorForBlock: self morph
at: position.
(c isKindOf: SBCursorText)
c := (c isKindOf: SBCursorText)
ifTrue: [SBCursorSelect new block: c block]
ifFalse: [c]]
ifFalse: [c].
c block selectable ifTrue: [c] ifFalse: [nil]]
ifFalse: [nil].
newCursor ~= cursor ifTrue: [
cursor ifNotNil: [self morph invalidRect: cursor bounds].
Expand Down

0 comments on commit e9dcb06

Please sign in to comment.