fix(text-actions): Calculate accumulated transform matrix for text inside groups (#1082)
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
check each push / build (push) Has been cancelled

When editing text inside a group element, the text cursor was appearing
in the wrong position because only the text element's own transform was
being considered, ignoring transforms from parent groups.

This change:
- Adds a new #getAccumulatedMatrix() method that traverses up the DOM tree
  from the text element to the SVG content element, collecting and multiplying
  all transform matrices along the way
- Updates the init() method to use this accumulated matrix instead of just
  the text element's transform
- Updates test mock to include getSvgContent() method

Fixes the issue where editing text inside a transformed group would show
the cursor at the wrong position.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Namhoon Lee
2026-02-04 22:57:35 +09:00
committed by GitHub
parent b9149f73cb
commit 0be0c3916c
2 changed files with 46 additions and 5 deletions

View File

@@ -18,12 +18,17 @@ describe('TextActions', () => {
svgRoot.setAttribute('height', '480')
document.body.append(svgRoot)
// Create svgContent element (container for SVG content)
const svgContent = document.createElementNS(NS.SVG, 'svg')
svgContent.id = 'svgcontent'
svgRoot.append(svgContent)
textElement = document.createElementNS(NS.SVG, 'text')
textElement.setAttribute('x', '100')
textElement.setAttribute('y', '100')
textElement.setAttribute('id', 'text1')
textElement.textContent = 'Test'
svgRoot.append(textElement)
svgContent.append(textElement)
// Mock text measurement methods
textElement.getStartPositionOfChar = vi.fn((i) => ({ x: 100 + i * 10, y: 100 }))
@@ -55,6 +60,7 @@ describe('TextActions', () => {
// Mock svgCanvas
svgCanvas = {
getSvgRoot: () => svgRoot,
getSvgContent: () => svgContent,
getZoom: () => 1,
setCurrentMode: vi.fn(),
clearSelection: vi.fn(),