Fix: applies the transformation of the parent element in addition to … (#839)
* Fix: applies the transformation of the parent element in addition to that of the selected element * Fix: delete debug logs and use a ternary operatormaster
parent
b6f8158200
commit
e2ad8211a5
|
@ -8,7 +8,8 @@
|
|||
|
||||
import { isWebkit } from '../../src/common/browser.js'
|
||||
import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js'
|
||||
import { transformListToTransform, transformBox, transformPoint } from './math.js'
|
||||
import { transformListToTransform, transformBox, transformPoint, matrixMultiply } from './math.js'
|
||||
import { NS } from './namespaces'
|
||||
|
||||
let svgCanvas
|
||||
let selectorManager_ // A Singleton
|
||||
|
@ -122,9 +123,24 @@ export class Selector {
|
|||
offset += 2 / zoom
|
||||
}
|
||||
|
||||
// find the transformations applied to the parent of the selected element
|
||||
const svg = document.createElementNS(NS.SVG, 'svg')
|
||||
let parentTransformationMatrix = svg.createSVGMatrix()
|
||||
let currentElt = selected
|
||||
while (currentElt.parentNode) {
|
||||
if (currentElt.parentNode && currentElt.parentNode.tagName === 'g' && currentElt.parentNode.transform) {
|
||||
if (currentElt.parentNode.transform.baseVal.numberOfItems) {
|
||||
parentTransformationMatrix = matrixMultiply(transformListToTransform(selected.parentNode.transform.baseVal).matrix, parentTransformationMatrix)
|
||||
}
|
||||
}
|
||||
currentElt = currentElt.parentNode
|
||||
}
|
||||
|
||||
// loop and transform our bounding box until we reach our first rotation
|
||||
const tlist = selected.transform.baseVal
|
||||
const m = transformListToTransform(tlist).matrix
|
||||
|
||||
// combines the parent transformation with that of the selected element if necessary
|
||||
const m = parentTransformationMatrix ? matrixMultiply(parentTransformationMatrix, transformListToTransform(tlist).matrix) : transformListToTransform(tlist).matrix
|
||||
|
||||
// This should probably be handled somewhere else, but for now
|
||||
// it keeps the selection box correctly positioned when zoomed
|
||||
|
|
Loading…
Reference in New Issue