From a916af3172333b55a8f6618e7d79f73eccf26c62 Mon Sep 17 00:00:00 2001 From: Alain Plantec Date: Mon, 18 Mar 2024 23:44:40 +0100 Subject: [PATCH] somes changes around cursorElement --- src/Album/AlbCursorElement.class.st | 4 +- .../AlbCursorElementEventHandler.class.st | 46 +++++++++++++++++++ src/Album/AlbCursorMovedEvent.class.st | 18 +++----- src/Album/AlbEditorElement.class.st | 1 + .../AlbEditorElementEventHandler.class.st | 18 ++++---- .../AlbOppositeDelimiterUpdater.class.st | 9 +--- src/Album/AlbTextDeletedEvent.class.st | 14 +++++- .../AlbTextEditorSegmentElement.class.st | 8 +--- src/Album/AlbTextInsertedEvent.class.st | 16 ++++++- src/Album/AlbTextParagraph.class.st | 8 +--- src/Album/TAlbInfiniteDecorator.trait.st | 13 ++++++ 11 files changed, 108 insertions(+), 47 deletions(-) create mode 100644 src/Album/AlbCursorElementEventHandler.class.st diff --git a/src/Album/AlbCursorElement.class.st b/src/Album/AlbCursorElement.class.st index 38536b5..19f7a82 100644 --- a/src/Album/AlbCursorElement.class.st +++ b/src/Album/AlbCursorElement.class.st @@ -54,7 +54,8 @@ AlbCursorElement >> initialize [ self preventMouseEvents. self constraintsDo: [ :c | c horizontal exact: 2. - c vertical matchParent ] + c vertical matchParent ]. + self addEventHandler: AlbCursorElementEventHandler new ] { #category : #initialization } @@ -106,6 +107,5 @@ AlbCursorElement >> textPosition [ { #category : #accessing } AlbCursorElement >> textPosition: anInteger [ - self fireEvent: AlbCursorElementMovedEvent new. textPosition := anInteger ] diff --git a/src/Album/AlbCursorElementEventHandler.class.st b/src/Album/AlbCursorElementEventHandler.class.st new file mode 100644 index 0000000..1ae5e6d --- /dev/null +++ b/src/Album/AlbCursorElementEventHandler.class.st @@ -0,0 +1,46 @@ +Class { + #name : #AlbCursorElementEventHandler, + #superclass : #BlCustomEventHandler, + #instVars : [ + 'previousBoundsInSpace' + ], + #category : #'Album-UI' +} + +{ #category : #'event handling' } +AlbCursorElementEventHandler >> elementAddedToSceneGraphEvent: anEvent [ + + self notifyCursorElementMovedFromEvent: anEvent +] + +{ #category : #'event handling' } +AlbCursorElementEventHandler >> elementExtentChangedEvent: anEvent [ + + self notifyCursorElementMovedFromEvent: anEvent +] + +{ #category : #'event handling' } +AlbCursorElementEventHandler >> elementPositionInSpaceChangedEvent: anEvent [ + + self notifyCursorElementMovedFromEvent: anEvent +] + +{ #category : #'api - accessing' } +AlbCursorElementEventHandler >> eventsToHandle [ + + ^ { + BlElementExtentChangedEvent. + BlElementAddedToSceneGraphEvent. + BlElementPositionInSpaceChangedEvent } +] + +{ #category : #'event handling' } +AlbCursorElementEventHandler >> notifyCursorElementMovedFromEvent: anEvent [ + + | cursorElement boundsInSpace | + cursorElement := anEvent currentTarget. + boundsInSpace := cursorElement bounds inSpace bounds. + previousBoundsInSpace = boundsInSpace ifTrue: [ ^ self ]. + previousBoundsInSpace := boundsInSpace. + anEvent currentTarget fireEvent: AlbCursorElementMovedEvent new +] diff --git a/src/Album/AlbCursorMovedEvent.class.st b/src/Album/AlbCursorMovedEvent.class.st index a15c3cd..8d0a558 100644 --- a/src/Album/AlbCursorMovedEvent.class.st +++ b/src/Album/AlbCursorMovedEvent.class.st @@ -7,19 +7,9 @@ Class { 'newIndex', 'dueTo' ], - #category : 'Album-Model-Events' + #category : #'Album-Model-Events' } -{ #category : #'instance creation' } -AlbCursorMovedEvent class >> cursor: aCursor from: anOldIndex to: aNewIndex [ - - - ^ self new - cursor: aCursor; - oldIndex: anOldIndex; - newIndex: aNewIndex -] - { #category : #'instance creation' } AlbCursorMovedEvent class >> cursor: aCursor from: anOldIndex to: aNewIndex dueTo: aTextEditorOperator [ @@ -76,3 +66,9 @@ AlbCursorMovedEvent >> oldIndex [ AlbCursorMovedEvent >> oldIndex: aNumber [ oldIndex := aNumber ] + +{ #category : #sending } +AlbCursorMovedEvent >> sendTo: anObject [ + + anObject cursorMovedEvent: self +] diff --git a/src/Album/AlbEditorElement.class.st b/src/Album/AlbEditorElement.class.st index 59e366c..7d8344e 100644 --- a/src/Album/AlbEditorElement.class.st +++ b/src/Album/AlbEditorElement.class.st @@ -100,6 +100,7 @@ AlbEditorElement >> initialize [ BlMouseEvent. BlElementScrolledEvent. AlbTextInsertedEvent. + AlbTextDeletedEvent. AlbTextEditedEvent. AlbInfiniteModeChangedEvent. BlFocusEvent. diff --git a/src/Album/AlbEditorElementEventHandler.class.st b/src/Album/AlbEditorElementEventHandler.class.st index 302c06b..ff9ecf2 100644 --- a/src/Album/AlbEditorElementEventHandler.class.st +++ b/src/Album/AlbEditorElementEventHandler.class.st @@ -10,6 +10,14 @@ AlbEditorElementEventHandler >> blurEvent: anEvent [ anEvent currentTarget primarySelectionElement dispatchEvent: anEvent copy ] +{ #category : #'element handlers' } +AlbEditorElementEventHandler >> cursorElementMovedEvent: anEvent [ + + | target | + target := anEvent currentTarget. + target dispatchPrimarySelectionInvalidateEvent +] + { #category : #'element handlers' } AlbEditorElementEventHandler >> elementExtentChangedEvent: anEvent [ @@ -31,7 +39,7 @@ AlbEditorElementEventHandler >> elementScrolledEvent: anEvent [ AlbEditorElementEventHandler >> eventsToHandle [ ^ { - BlMouseUpEvent. + AlbCursorElementMovedEvent. AlbInfiniteModeChangedEvent. AlbPrimarySelectionElementClassChangedEvent. BlElementExtentChangedEvent. @@ -55,14 +63,6 @@ AlbEditorElementEventHandler >> infiniteModeChangedEvent: anEvent [ target dispatchPrimarySelectionInvalidateEvent ] -{ #category : #'element handlers' } -AlbEditorElementEventHandler >> mouseUpEvent: anEvent [ - - | target | - target := anEvent currentTarget. - target dispatchPrimarySelectionInvalidateEvent -] - { #category : #'event handling' } AlbEditorElementEventHandler >> primarySelectionElementClassChangedEvent: anEvent [ diff --git a/src/Album/AlbOppositeDelimiterUpdater.class.st b/src/Album/AlbOppositeDelimiterUpdater.class.st index 54b39da..7af80b5 100644 --- a/src/Album/AlbOppositeDelimiterUpdater.class.st +++ b/src/Album/AlbOppositeDelimiterUpdater.class.st @@ -59,19 +59,12 @@ AlbOppositeDelimiterUpdater >> createOppositeDelimiterIn: anEditorElement [ ^ nil ] -{ #category : #'event handling' } -AlbOppositeDelimiterUpdater >> cursorElementMovedEvent: anEvent [ - - self updateOppositeDelimiterIn: anEvent currentTarget. -] - { #category : #'api - accessing' } AlbOppositeDelimiterUpdater >> eventsToHandle [ ^ { AlbSubtextElementInvalidateEvent. - AlbInfiniteModeChangedEvent. - AlbCursorElementMovedEvent } + AlbInfiniteModeChangedEvent } ] { #category : #'event handling' } diff --git a/src/Album/AlbTextDeletedEvent.class.st b/src/Album/AlbTextDeletedEvent.class.st index 9b5fd7b..dc841f6 100644 --- a/src/Album/AlbTextDeletedEvent.class.st +++ b/src/Album/AlbTextDeletedEvent.class.st @@ -5,7 +5,7 @@ Class { 'fromIndex', 'toIndex' ], - #category : 'Album-Model-Events' + #category : #'Album-Model-Events' } { #category : #'instance creation' } @@ -27,6 +27,18 @@ AlbTextDeletedEvent >> fromIndex: anObject [ fromIndex := anObject ] +{ #category : #sending } +AlbTextDeletedEvent >> sendTo: anObject [ + + anObject textDeletedEvent: self +] + +{ #category : #accessing } +AlbTextDeletedEvent >> startIndex [ + + ^ self fromIndex +] + { #category : #accessing } AlbTextDeletedEvent >> toIndex [ ^ toIndex diff --git a/src/Album/AlbTextEditorSegmentElement.class.st b/src/Album/AlbTextEditorSegmentElement.class.st index 8d99916..1b6caa8 100644 --- a/src/Album/AlbTextEditorSegmentElement.class.st +++ b/src/Album/AlbTextEditorSegmentElement.class.st @@ -8,7 +8,7 @@ Override me for more advanced customizations Class { #name : #AlbTextEditorSegmentElement, #superclass : #BlElement, - #category : 'Album-UI' + #category : #'Album-UI' } { #category : #initialization } @@ -16,9 +16,3 @@ AlbTextEditorSegmentElement >> initialize [ super initialize. self clipChildren: false ] - -{ #category : #'api - compositing' } -AlbTextEditorSegmentElement >> wantsSeparateCompositingLayer [ - - ^ false -] diff --git a/src/Album/AlbTextInsertedEvent.class.st b/src/Album/AlbTextInsertedEvent.class.st index 61b0c18..7eacdd7 100644 --- a/src/Album/AlbTextInsertedEvent.class.st +++ b/src/Album/AlbTextInsertedEvent.class.st @@ -18,9 +18,9 @@ AlbTextInsertedEvent class >> text: aBlText at: anIndex [ ] { #category : #accessing } -AlbTextInsertedEvent >> endIndex [ +AlbTextInsertedEvent >> fromIndex [ - ^ self index + self text size + ^ self index ] { #category : #accessing } @@ -33,6 +33,12 @@ AlbTextInsertedEvent >> index: aNumber [ index := aNumber ] +{ #category : #sending } +AlbTextInsertedEvent >> sendTo: anEventHandler [ + + anEventHandler textInsertedEvent: self +] + { #category : #accessing } AlbTextInsertedEvent >> text [ ^ text @@ -42,3 +48,9 @@ AlbTextInsertedEvent >> text [ AlbTextInsertedEvent >> text: aText [ text := aText ] + +{ #category : #accessing } +AlbTextInsertedEvent >> toIndex [ + + ^ self index + self text size +] diff --git a/src/Album/AlbTextParagraph.class.st b/src/Album/AlbTextParagraph.class.st index 4bfd0db..28bfc61 100644 --- a/src/Album/AlbTextParagraph.class.st +++ b/src/Album/AlbTextParagraph.class.st @@ -7,7 +7,7 @@ Class { #instVars : [ 'segmentPiece' ], - #category : 'Album-UI' + #category : #'Album-UI' } { #category : #'paragraph - measuring' } @@ -21,9 +21,3 @@ AlbTextParagraph >> segmentPiece: aSegmentPiece [ segmentPiece := aSegmentPiece ] - -{ #category : #'api - compositing' } -AlbTextParagraph >> wantsSeparateCompositingLayer [ - - ^ false -] diff --git a/src/Album/TAlbInfiniteDecorator.trait.st b/src/Album/TAlbInfiniteDecorator.trait.st index 900ecf8..5301795 100644 --- a/src/Album/TAlbInfiniteDecorator.trait.st +++ b/src/Album/TAlbInfiniteDecorator.trait.st @@ -15,6 +15,13 @@ TAlbInfiniteDecorator >> asScrollableElement [ ^ self next asScrollableElement ] +{ #category : #'t - infinite editor private - accessing text' } +TAlbInfiniteDecorator >> atTextIndex: aTextIndex do: aBlock [ + + " aBlock takes 2 arguments : the local text element and the local text index within the local text element" + self next atTextIndex: aTextIndex do: aBlock +] + { #category : #'t - infinite editor view - configuration' } TAlbInfiniteDecorator >> beEditable [ @@ -57,6 +64,12 @@ TAlbInfiniteDecorator >> cursorColor: aColor [ self next cursorColor: aColor ] +{ #category : #'t - infinite editor accessing - cursor' } +TAlbInfiniteDecorator >> cursorElement [ + + ^ self next cursorElement +] + { #category : #'t - infinite editor accessing - cursor' } TAlbInfiniteDecorator >> cursors [