Skip to content

Commit

Permalink
core: move suggestions helper to class-side
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Oct 3, 2023
1 parent 1f0ad08 commit 89dae6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
56 changes: 30 additions & 26 deletions packages/Sandblocks-Core/SBBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ SBBlock class >> navigation: aNavigation [
Navigation := aNavigation
]

{ #category : #'as yet unclassified' }
SBBlock class >> sortedSuggestions: aCollection for: aString addAll: aBoolean max: aNumber [

| exactMatches fuzzyMatches list |
"sort list of provided suggestion strings by putting exact matches first and clamps to maxSuggestions.
NOTE: may mutate aCollection"
list := (aCollection isKindOf: OrderedCollection)
ifTrue: [aCollection]
ifFalse: [OrderedCollection withAll: aCollection].
exactMatches := (Array streamContents: [:stream |
list removeAllSuchThat: [:sel |
(sel sandblockBeginsWith: aString)
ifTrue: [stream nextPut: sel];
yourself]]) sort: #size ascending.
fuzzyMatches := (Array streamContents: [:stream |
list removeAllSuchThat: [:sel |
(sel sandblockMatch: aString)
ifTrue: [stream nextPut: sel];
yourself]]) sort: #size ascending.
^ (Array
streamContents: [:stream |
stream nextPutAll: exactMatches.
stream nextPutAll: fuzzyMatches.
aBoolean ifTrue: [stream nextPutAll: list]]
limitedTo: aNumber) withoutDuplicates
]

{ #category : #input }
SBBlock >> absorbsInput: anEvent [
" a chance for you to block this event from being dispatched as shortcut "
Expand Down Expand Up @@ -666,7 +694,7 @@ SBBlock >> containingToplevel [
{ #category : #accessing }
SBBlock >> contents [

^ self currentTextMorph ifNotNil: [:t | t contents]
^ self currentTextMorph ifNotNil: [:t | t contents] ifNil: ['']
]

{ #category : #accessing }
Expand Down Expand Up @@ -2751,31 +2779,7 @@ SBBlock >> slurpFront [
{ #category : #suggestions }
SBBlock >> sortedSuggestions: aCollection for: aString [

| exactMatches fuzzyMatches list |
"sort list of provided suggestion strings by putting exact matches first and clamps to maxSuggestions.
NOTE: may mutate aCollection"
list := (aCollection isKindOf: OrderedCollection)
ifTrue: [aCollection]
ifFalse: [OrderedCollection withAll: aCollection].

exactMatches := (Array streamContents: [:stream |
list removeAllSuchThat: [:sel |
(sel sandblockBeginsWith: aString)
ifTrue: [stream nextPut: sel];
yourself]]) sort: #size ascending.
fuzzyMatches := (Array streamContents: [:stream |
list removeAllSuchThat: [:sel |
(sel sandblockMatch: aString)
ifTrue: [stream nextPut: sel];
yourself]]) sort: #size ascending.

^ (Array
streamContents: [:stream |
stream nextPutAll: exactMatches.
stream nextPutAll: fuzzyMatches.
self suggestAlways ifTrue: [stream nextPutAll: list]]
limitedTo: self maxSuggestions) withoutDuplicates
^ self class sortedSuggestions: aCollection for: aString addAll: self suggestAlways max: self maxSuggestions
]

{ #category : #'ast helpers' }
Expand Down
6 changes: 6 additions & 0 deletions packages/Sandblocks-Morphs/SBOwnTextMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ SBOwnTextMorph >> bold [
self emphasis: TextEmphasis bold
]

{ #category : #'as yet unclassified' }
SBOwnTextMorph >> characterAfterCursor [

^ self cursor > self contents size ifTrue: [nil] ifFalse: [self contents at: self cursor]
]

{ #category : #'as yet unclassified' }
SBOwnTextMorph >> characterBeforeCursor [

Expand Down

0 comments on commit 89dae6b

Please sign in to comment.