refactor(text): update TextEditor to use TextSprite API

This commit is contained in:
Hiren Kangad
2026-03-12 22:09:12 +05:30
parent 2e24500746
commit 2efcd0e622
+12 -16
View File
@@ -6,12 +6,12 @@
* Commits on blur/Enter, cancels on Escape. * Commits on blur/Enter, cancels on Escape.
*/ */
import { Text } from 'pixi.js';
import type { Viewport } from 'pixi-viewport'; import type { Viewport } from 'pixi-viewport';
import type { SceneItem } from './SceneManager'; import type { SceneItem } from './SceneManager';
import type { TextObject } from './scene-format'; import type { TextObject } from './scene-format';
import type { StickyObject } from './scene-format'; import type { StickyObject } from './scene-format';
import { StickySprite } from './sprites/StickySprite'; import { StickySprite } from './sprites/StickySprite';
import { TextSprite } from './sprites/TextSprite';
export class TextEditor { export class TextEditor {
private _textarea: HTMLTextAreaElement | null = null; private _textarea: HTMLTextAreaElement | null = null;
@@ -104,10 +104,9 @@ export class TextEditor {
screenY = screen.y; screenY = screen.y;
taWidth = 'auto'; taWidth = 'auto';
// Hide the PixiJS text while editing // Hide the TextSprite text while editing
const pixiText = item.displayObject; if (item.displayObject instanceof TextSprite) {
if (pixiText instanceof Text) { item.displayObject.showText(false);
pixiText.visible = false;
} }
} }
@@ -228,15 +227,13 @@ export class TextEditor {
item.displayObject.showText(true); item.displayObject.showText(true);
onChange?.(); onChange?.();
} else if (item.type === 'text') { } else if (item.type === 'text') {
const pixiText = item.displayObject; if (item.displayObject instanceof TextSprite && !item.displayObject.destroyed) {
if (pixiText instanceof Text && !pixiText.destroyed) {
const data = item.data as TextObject; const data = item.data as TextObject;
data.text = newText; data.text = newText;
pixiText.text = newText; item.displayObject.updateFromData(data);
pixiText.visible = true; data.w = item.displayObject.measuredWidth;
const bounds = pixiText.getLocalBounds(); data.h = item.displayObject.measuredHeight;
data.w = bounds.width; item.displayObject.showText(true);
data.h = bounds.height;
onChange?.(); onChange?.();
} }
} }
@@ -253,12 +250,11 @@ export class TextEditor {
data.h = item.displayObject.computedHeight; data.h = item.displayObject.computedHeight;
item.displayObject.showText(true); item.displayObject.showText(true);
} else if (item.type === 'text') { } else if (item.type === 'text') {
const pixiText = item.displayObject; if (item.displayObject instanceof TextSprite && !item.displayObject.destroyed) {
if (pixiText instanceof Text && !pixiText.destroyed) {
const data = item.data as TextObject; const data = item.data as TextObject;
data.text = originalText; data.text = originalText;
pixiText.text = originalText; item.displayObject.updateFromData(data);
pixiText.visible = true; item.displayObject.showText(true);
} }
} }
// Always notify on cancel too — the tool callback needs this // Always notify on cancel too — the tool callback needs this