Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrTextEditorSelectionHandler: Only update the cursor at the end of a drag #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
65 changes: 50 additions & 15 deletions src/Brick-Editor/BrTextEditorSelectionHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,83 @@ Class {
#instVars : [
'startIndex'
],
#category : 'Brick-Editor-UI - Handlers'
#category : #'Brick-Editor-UI - Handlers'
}

{ #category : #'dnd handlers' }
BrTextEditorSelectionHandler >> dragEndEvent: anEvent [
"I end a selection at an event's editor, while also updating the cursor."

| anEditor currentIndex |
anEvent consumed: true.

anEditor := anEvent currentTarget editor.

currentIndex := anEditor navigator
findTextIndexAtScreenPosition: anEvent localPosition
ifAbsent: [ ^ self ].

self
assert: [ currentIndex between: 0 and: anEditor text size ]
description: [ 'Text index ({1}) must be within text bounds {2}'
format: {currentIndex.
0 to: anEditor text size} ].

startIndex ifNil: [ startIndex := currentIndex ].

anEditor selecter
overwrite;
from: (startIndex min: currentIndex) to: (startIndex max: currentIndex);
select
]

{ #category : #'dnd handlers' }
BrTextEditorSelectionHandler >> dragEvent: anEvent [
| anEditor currentIndex |
"I update an event's editor selection, upon a mouse drag.
For performance reasons I make sure to not update the cursor with the selection."

| anEditor currentIndex |
anEvent consumed: true.

anEditor := anEvent currentTarget editor.

currentIndex := anEditor navigator
findTextIndexAtScreenPosition: anEvent localPosition
ifAbsent: [ ^ self ].
findTextIndexAtScreenPosition: anEvent localPosition
ifAbsent: [ ^ self ].

self
assert: [ currentIndex between: 0 and: anEditor text size ]
description: [ 'Text index ({1}) must be within text bounds {2}'
format: { currentIndex . 0 to: anEditor text size } ].

format: {currentIndex.
0 to: anEditor text size} ].

startIndex ifNil: [ startIndex := currentIndex ].

anEditor selecter
overwrite;
from: (startIndex min: currentIndex)
to: (startIndex max: currentIndex);
withoutCursorUpdate;
from: (startIndex min: currentIndex) to: (startIndex max: currentIndex);
select
]

{ #category : #'dnd handlers' }
BrTextEditorSelectionHandler >> dragStartEvent: anEvent [
| anEditor |
"I initiate a selection at an event's editor."

| anEditor |
anEvent consumed: true.

anEditor := anEvent currentTarget editor.
anEditor deselecter all deselect.

startIndex := anEditor navigator
findTextIndexAtScreenPosition: anEvent localPosition
ifAbsent: [ nil ].
findTextIndexAtScreenPosition: anEvent localPosition
ifAbsent: [ nil ]
]

{ #category : #'api - accessing' }
BrTextEditorSelectionHandler >> eventsToHandle [
^ { BlDragEvent . BlDragStartEvent }
^ {BlDragEvent.
BlDragStartEvent.
BlDragEndEvent}
]