-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[997] Prevent the cursor mouse listener to trigger unwanted update model
When the model is updated after a new version of the diagram has been sent by the backend, the next time the cursor mouse listener is triggered (at the next mouse move), it updates the model and thus, forces sprotty to render the diagram again. Sometime it may look like the diagram is blinking especially when an edge is selected and one of its routing points has been modified. Bug: #997 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
- Loading branch information
1 parent
b619827
commit 65f3986
Showing
7 changed files
with
73 additions
and
46 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
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
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
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
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
51 changes: 51 additions & 0 deletions
51
...es/diagrams/frontend/sirius-components-diagrams/src/sprotty/common/CursorMouseListener.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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { decorate, inject } from 'inversify'; | ||
import { MouseListener, TYPES } from 'sprotty'; | ||
import { UpdateModelAction } from 'sprotty-protocol'; | ||
import { DiagramServer } from '../DiagramServer'; | ||
|
||
/** | ||
* Update the cursor if need. | ||
* | ||
* It triggers a model update every time the cursor has to change. This will trigger a rendering that will use the new cursor value. | ||
*/ | ||
export class CursorMouseListener extends MouseListener { | ||
constructor(protected readonly diagramServer: DiagramServer) { | ||
super(); | ||
} | ||
|
||
override mouseMove(element, _event) { | ||
const root = element.root; | ||
const elementWithTarget = findElementWithTarget(element); | ||
const expectedCursor = this.diagramServer.getCursorOn(elementWithTarget, this.diagramServer); | ||
if (root.cursor !== expectedCursor) { | ||
root.cursor = expectedCursor; | ||
return [UpdateModelAction.create(root)]; | ||
} | ||
|
||
return []; | ||
} | ||
} | ||
decorate(inject(TYPES.ModelSource) as ParameterDecorator, CursorMouseListener, 0); | ||
|
||
const findElementWithTarget = (element) => { | ||
if (element.targetObjectId) { | ||
return element; | ||
} else if (element.parent) { | ||
return findElementWithTarget(element.parent); | ||
} | ||
// Otherwise, use the diagram as element with target. | ||
return element.root; | ||
}; |
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