Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Spec2-Core/SpAbstractTextPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ SpAbstractTextPresenter >> selectAll [
self selectionInterval: (1 to: self text size)
]

{ #category : 'api - selection' }
SpAbstractTextPresenter >> selectFirst: aString ifAbsent: aBlock [

| index |
index := self text findString: aString.
index = 0 ifTrue: [ ^ aBlock value ].
self selectionInterval: (index to: index + aString size -1)

]

{ #category : 'api - selection' }
SpAbstractTextPresenter >> selectLine [
"Select line where the cursor is placed at this moment and answer the resulting selection
Expand Down
33 changes: 33 additions & 0 deletions src/Spec2-Tests/SpAbstractTextPresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,39 @@ SpAbstractTextPresenterTest >> testSelectAllWithoutOpening [
self assert: presenter selectionInterval equals: (1 to: 15)
]

{ #category : 'tests' }
SpAbstractTextPresenterTest >> testSelectFirst [

| startIndex |
self initializationText.
presenter selectFirst: 'for' ifAbsent: [ ].
startIndex := presenter text findString: 'for'.

self assert: presenter selectionInterval equals: (startIndex to: startIndex+2)
]

{ #category : 'tests' }
SpAbstractTextPresenterTest >> testSelectFirstWhenAbsent [

| startIndex passByAbsent |
self initializationText.
passByAbsent := false.
presenter selectFirst: 'ZZZ' ifAbsent: [ passByAbsent := true ].
startIndex := presenter text findString: 'for'.

self assertEmpty: presenter selectionInterval.
self assert: passByAbsent
]

{ #category : 'tests' }
SpAbstractTextPresenterTest >> testSelectFirstWhenMultiplePossibleSelection [

presenter text: 'this is a test'.
presenter selectFirst: 'is' ifAbsent: [ ].

self assert: presenter selectionInterval equals: (3 to: 4)
]

{ #category : 'tests' }
SpAbstractTextPresenterTest >> testTextIsSetAndCursorPositionedCorrectly [

Expand Down
Loading