-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
155 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
packages/editor/src/accessibility/element-navigation/diagram-navigation-tool.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
13 changes: 0 additions & 13 deletions
13
packages/editor/src/accessibility/key-shortcut/accessible-key-shortcut-tool.ts
This file was deleted.
Oops, something went wrong.
141 changes: 141 additions & 0 deletions
141
packages/editor/src/accessibility/view-key-tool/movement-key-tool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { | ||
Action, | ||
BoundsAware, | ||
boundsFeature, | ||
ChangeBoundsOperation, | ||
ElementAndBounds, | ||
findParentByFeature, | ||
GChildElement, | ||
getElements, | ||
GModelElement, | ||
Grid, | ||
IMovementRestrictor, | ||
isBoundsAware, | ||
isViewport, | ||
matchesKeystroke, | ||
MoveKeyListener, | ||
MovementKeyTool, | ||
Point, | ||
SetUIExtensionVisibilityAction, | ||
SetViewportAction, | ||
toElementAndBounds, | ||
TYPES, | ||
Viewport | ||
} from '@eclipse-glsp/client'; | ||
import { inject, injectable, optional } from 'inversify'; | ||
import { QuickActionUI } from '../../ui-tools/quick-action/quick-action-ui'; | ||
|
||
@injectable() | ||
export class IvyMovementKeyTool extends MovementKeyTool { | ||
@inject(TYPES.IMovementRestrictor) @optional() readonly movementRestrictor: IMovementRestrictor; | ||
|
||
enable(): void { | ||
if (!this.movementKeyListener) { | ||
this.movementKeyListener = new IvyMoveKeyListener(this, this.grid); | ||
} | ||
this.keytool.register(this.movementKeyListener); | ||
this.movementKeyListener.registerShortcutKey(); | ||
} | ||
} | ||
|
||
@injectable() | ||
class IvyMoveKeyListener extends MoveKeyListener { | ||
constructor( | ||
protected readonly tool: IvyMovementKeyTool, | ||
protected grid: Grid = { x: MoveKeyListener.defaultMoveX, y: MoveKeyListener.defaultMoveY } | ||
) { | ||
super(tool, grid); | ||
} | ||
|
||
keyDown(element: GModelElement, event: KeyboardEvent): Action[] { | ||
const delta = this.moveDelta(event); | ||
if (delta === undefined) { | ||
return []; | ||
} | ||
if (this.tool.selectionService.hasSelectedElements()) { | ||
return this.moveElements(delta); | ||
} | ||
return this.moveGraph(element, delta); | ||
} | ||
|
||
protected moveDelta(event: KeyboardEvent) { | ||
if (matchesKeystroke(event, 'ArrowUp')) { | ||
return { x: 0, y: -this.grid.y }; | ||
} | ||
if (matchesKeystroke(event, 'ArrowDown')) { | ||
return { x: 0, y: this.grid.y }; | ||
} | ||
if (matchesKeystroke(event, 'ArrowLeft')) { | ||
return { x: -this.grid.x, y: 0 }; | ||
} | ||
if (matchesKeystroke(event, 'ArrowRight')) { | ||
return { x: this.grid.x, y: 0 }; | ||
} | ||
return undefined; | ||
} | ||
|
||
protected moveGraph(element: GModelElement, delta: Point) { | ||
const model = findParentByFeature(element, isViewport); | ||
if (model === undefined) { | ||
return []; | ||
} | ||
const newViewport: Viewport = { | ||
scroll: { | ||
x: model.scroll.x + delta.x, | ||
y: model.scroll.y + delta.y | ||
}, | ||
zoom: model.zoom | ||
}; | ||
return [SetViewportAction.create(model.id, newViewport, { animate: false })]; | ||
} | ||
|
||
protected moveElements(delta: Point): Action[] { | ||
let selectedElements = getElements( | ||
this.tool.selectionService.getModelRoot().index, | ||
Array.from(this.tool.selectionService.getSelectedElementIDs()), | ||
isBoundsAware | ||
); | ||
selectedElements = selectedElements.filter(e => !this.isChildOfSelected(selectedElements, e)).filter(e => e.hasFeature(boundsFeature)); | ||
if (selectedElements.length === 0) { | ||
return []; | ||
} | ||
|
||
const newBounds = selectedElements.filter(e => this.isMovementAllowed(e, delta)).map(e => this.getElementAndUpdatedBound(e, delta)); | ||
if (newBounds.length !== selectedElements.length) { | ||
return []; | ||
} | ||
return [ | ||
ChangeBoundsOperation.create(newBounds), | ||
SetUIExtensionVisibilityAction.create({ | ||
extensionId: QuickActionUI.ID, | ||
visible: true, | ||
contextElementsId: [...selectedElements.map(e => e.id)] | ||
}) | ||
]; | ||
} | ||
|
||
protected isChildOfSelected(selectedElements: GModelElement[], element: GModelElement): boolean { | ||
return element instanceof GChildElement && selectedElements.includes(element.parent); | ||
} | ||
|
||
protected isMovementAllowed(element: GModelElement & BoundsAware, delta: Point): boolean { | ||
if (this.tool.movementRestrictor) { | ||
const newPosition = this.updatePosition(element, delta); | ||
return this.tool.movementRestrictor.validate(element, newPosition); | ||
} | ||
return true; | ||
} | ||
|
||
protected getElementAndUpdatedBound(element: GModelElement & BoundsAware, delta: Point): ElementAndBounds { | ||
const bound = toElementAndBounds(element); | ||
bound.newPosition = this.updatePosition(element, delta); | ||
return bound; | ||
} | ||
|
||
protected updatePosition(element: GModelElement & BoundsAware, delta: Point): Point { | ||
return { | ||
x: element.bounds.x + delta.x, | ||
y: element.bounds.y + delta.y | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters