fix(text): use requestAnimationFrame for editor open timing

queueMicrotask fires before the click event settles, causing the
textarea to blur immediately and trigger empty-text cleanup.
requestAnimationFrame waits one paint frame — enough for the pointer
event to fully resolve without the sluggishness of setTimeout(50).
This commit is contained in:
Hiren Kangad
2026-03-12 22:15:20 +05:30
parent d365049470
commit 93c7c792db
+4 -4
View File
@@ -130,8 +130,8 @@ export function activateTool(
const canvasEl = container.querySelector('canvas');
const domContainer = canvasEl?.parentElement ?? container;
// Use microtask instead of 50ms delay — PixiJS only needs one tick
queueMicrotask(() => {
// Wait one frame so the click event settles before focusing textarea
requestAnimationFrame(() => {
ctx.textEditor!.startEditing(item, viewport, domContainer, () => {
// If user saved empty text, remove the item
const text = (item.data as any).text?.trim();
@@ -359,8 +359,8 @@ export function activateTool(
const canvasEl = container.querySelector('canvas');
const domContainer = canvasEl?.parentElement ?? container;
// Use microtask instead of 50ms delay — PixiJS only needs one tick
queueMicrotask(() => {
// Wait one frame so the click event settles before focusing textarea
requestAnimationFrame(() => {
ctx.textEditor!.startEditing(item, viewport, domContainer, () => {
// Cleanup rule — fires on BOTH save and cancel (stopEditing always calls _onChange):
// - new sticky + cancel/blur with empty text => remove (no blank notes left behind)