fix(m01-easycalc): 카드가 옛 판본을 쥐던 흠(저장 뒤 409) · 되돌리기 칸 다시 그림 · 단위 후보 다듬음 · 본뜬 뒤 알림
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PSXsvyDxjNmufteN5bqmt
This commit is contained in:
@@ -238,13 +238,16 @@ function openEasyCalc(): void {
|
||||
drawFound();
|
||||
};
|
||||
|
||||
/** 단위 고르기 후보 — 목록에 많이 쓰인 「원/…」 차례 */
|
||||
/** 단위 고르기 후보 — 목록에 다섯 번 넘게 쓰인 「원/…」 차례 · 설명 붙은 드문 단위는 뺌(연 로직 것은 따로 더함) */
|
||||
const unitChoices = (): string[] => {
|
||||
const count = new Map<string, number>();
|
||||
for (const x of logics ?? []) {
|
||||
if (x.canOpen) count.set(x.resultUnit, (count.get(x.resultUnit) ?? 0) + 1);
|
||||
}
|
||||
return [...count.entries()].sort((a, b) => b[1] - a[1]).map(([u]) => u);
|
||||
return [...count.entries()]
|
||||
.filter(([u, n]) => n >= 5 && !/[\s()「·]/.test(u))
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.map(([u]) => u);
|
||||
};
|
||||
|
||||
/* ---------- 고치는 화면 ---------- */
|
||||
@@ -336,8 +339,8 @@ function openEasyCalc(): void {
|
||||
baseBar.hidden = !doc.isBase;
|
||||
};
|
||||
|
||||
/** 금액 · 카드 · 표 — 계산 답이 올 때마다 · 바뀔 때마다 */
|
||||
const draw = (pending: boolean): void => {
|
||||
/** 금액 · 카드 · 표 — 바뀔 때마다(pending) · 계산 답이 올 때마다(answer) */
|
||||
const draw = (pending: boolean, answer = false): void => {
|
||||
const value = ans?.ok ? formatMoney(ans.result ?? ans.sums?.["계"] ?? 0) : "—";
|
||||
total.textContent = te("Total", { u: amountOf(doc.resultUnit), v: value });
|
||||
total.classList.toggle("is-pending", pending);
|
||||
@@ -352,15 +355,28 @@ function openEasyCalc(): void {
|
||||
calc();
|
||||
});
|
||||
}
|
||||
drawCards();
|
||||
drawCards(answer);
|
||||
renderSheet(sheetHost, { name: doc.name, resultUnit: doc.resultUnit }, ans);
|
||||
};
|
||||
|
||||
/** 카드 칸에 글을 넣는 중이면 그 칸을 떠난 뒤 그림(넣던 글이 안 날아가게) */
|
||||
const drawCards = (): void => {
|
||||
const typing = cardsHost.contains(document.activeElement) && document.activeElement !== null;
|
||||
if (typing && document.activeElement instanceof HTMLInputElement) {
|
||||
cardsHost.addEventListener("focusout", () => setTimeout(drawCards), { once: true });
|
||||
/** 계산 답만 왔을 때 카드 칸에 글을 넣는 중이면 그 칸을 떠난 뒤 그림(넣던 글이 안 날아가게).
|
||||
* doc 가 바뀌면 늘 바로 그림 — 카드가 옛 doc 를 쥐고 있으면 그다음 조작이 옛 판본 위에 쌓임 */
|
||||
let waiting = false;
|
||||
const drawCards = (answer = false): void => {
|
||||
const active = document.activeElement;
|
||||
if (answer && active instanceof HTMLInputElement && cardsHost.contains(active)) {
|
||||
if (!waiting) {
|
||||
waiting = true;
|
||||
cardsHost.addEventListener(
|
||||
"focusout",
|
||||
() =>
|
||||
setTimeout(() => {
|
||||
waiting = false;
|
||||
drawCards(true);
|
||||
}),
|
||||
{ once: true },
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
renderCards(cardsHost, doc, ans, { change: edit });
|
||||
@@ -371,7 +387,7 @@ function openEasyCalc(): void {
|
||||
calcLater(toRow(doc), trial, (next, plain) => {
|
||||
ans = next;
|
||||
note.textContent = plain ?? "";
|
||||
draw(false);
|
||||
draw(false, true);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -430,7 +446,7 @@ function openEasyCalc(): void {
|
||||
try {
|
||||
const saved = await copyEasy(doc.key);
|
||||
reopen(toDoc(saved.row, { key: saved.key, version: saved.version, isBase: false }));
|
||||
note.textContent = te("Copied");
|
||||
showToast(te("Copied"), "success");
|
||||
} catch (error) {
|
||||
note.textContent = plainError(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user