mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
chore: add test helpers for connecting blocks (#7258)
* chore: get procedure test passing on linux * chore: cleanup * chore: format
This commit is contained in:
@@ -262,7 +262,6 @@ export class RenderedConnection extends Connection {
|
||||
* Get the offset of this connection relative to the top left of its block.
|
||||
*
|
||||
* @returns The offset of the connection.
|
||||
* @internal
|
||||
*/
|
||||
getOffsetInBlock(): Coordinate {
|
||||
return this.offsetInBlock;
|
||||
|
||||
@@ -175,6 +175,34 @@ export function screenToWsCoordinates(
|
||||
return finalOffsetMainWs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts workspace coordinates to screen coordinates.
|
||||
*
|
||||
* @param ws The workspace to get the coordinates out of.
|
||||
* @param workspaceCoordinates The workspace coordinates to be converted
|
||||
* to screen coordinates.
|
||||
* @returns The screen coordinates.
|
||||
*/
|
||||
export function wsToScreenCoordinates(
|
||||
ws: WorkspaceSvg,
|
||||
workspaceCoordinates: Coordinate
|
||||
): Coordinate {
|
||||
// Fix workspace scale vs browser scale.
|
||||
const screenCoordinates = workspaceCoordinates.scale(ws.scale);
|
||||
const screenX = screenCoordinates.x;
|
||||
const screenY = screenCoordinates.y;
|
||||
|
||||
const injectionDiv = ws.getInjectionDiv();
|
||||
const boundingRect = injectionDiv.getBoundingClientRect();
|
||||
const mainOffset = ws.getOriginOffsetInPixels();
|
||||
|
||||
// Fix workspace origin vs browser origin.
|
||||
return new Coordinate(
|
||||
screenX + boundingRect.left + mainOffset.x,
|
||||
screenY + boundingRect.top + mainOffset.y
|
||||
);
|
||||
}
|
||||
|
||||
export const TEST_ONLY = {
|
||||
XY_REGEX,
|
||||
XY_STYLE_REGEX,
|
||||
|
||||
Reference in New Issue
Block a user