/* ============================================================================= * B05_Profile_UI_RouteEdit_UndoOwner.ts * 한 화면 두 이력(345-3) — 평면(노선 편집)과 종단도가 둘 다 창(window)에서 Ctrl+Z · Y 를 듣는다. * **마지막에 만진 판 하나만** 받는다: 누른 자리(평면 `.b05-routeedit` · 종단 판 `.b05-route-profile`)를 * 기억해 두고, 각 듣는 쪽이 받기 전에 묻는다. 평면이 안 듣는 동안(보기 숨김 · 떠남)은 늘 종단도. * 한 줄 되돌리기로 합치는 일은 346-4. * ========================================================================== */ export type UndoPanel = "plan" | "profile"; let last: UndoPanel = "profile"; let planListening = false; let bound = false; function remember(event: Event): void { const target = event.target as Element | null; if (!target?.closest) return; if (target.closest(".b05-routeedit")) last = "plan"; else if (target.closest(".b05-route-profile")) last = "profile"; } /** 평면 이력이 듣기 시작 · 멈춤 — 보기가 보일 때 켜고 숨을 때 끈다. */ export function setPlanUndoListening(on: boolean): void { planListening = on; if (bound) return; bound = true; window.addEventListener("pointerdown", remember, true); } /** 지금 Ctrl+Z · Y 를 받을 판. */ export function undoOwner(): UndoPanel { return planListening && last === "plan" ? "plan" : "profile"; }