fix(spreadsheet): 단위 Φ 앞붙이기 — 강제 글 낫표 뒤에 붙임 · 식은 그대로(81-5)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MgChuAcyBqUkhHMTXomQC7
This commit is contained in:
@@ -103,6 +103,15 @@ export function attachUnitToFormat(code: string, unit: string): string {
|
||||
return `"${unit}"` + plain;
|
||||
}
|
||||
|
||||
/** 앞 단위를 글 앞에 붙임(「300」 → 「Φ300」) — 글 낫표(강제 글 `'300`)는 맨 앞에 두고 그 뒤에
|
||||
* 붙임(`'Φ300` → 칸 값 「Φ300」) · 이미 붙어 있거나 식(`=`)이면 그대로 */
|
||||
export function prefixUnit(text: string, unit: string): string {
|
||||
if (text.startsWith("=")) return text;
|
||||
const lead = text.startsWith("'") ? "'" : "";
|
||||
const body = text.slice(lead.length);
|
||||
return body.startsWith(unit) ? text : lead + unit + body;
|
||||
}
|
||||
|
||||
/** 활성 칸에 지금 걸린 서식 — 칸 자기 것 없으면 열 · 행 · 시트 기본(`Sheet.기본.서식`) · 그다음 0. */
|
||||
function styleAt(ctx: SpreadsheetContext, r: number, c: number): CellStyle {
|
||||
const sheet = ctx.sheet();
|
||||
@@ -405,13 +414,18 @@ export function mountToolbar(ctx: SpreadsheetContext): PartHandle {
|
||||
if (ctx.editor.editing()) {
|
||||
const active = document.activeElement;
|
||||
if (active instanceof HTMLTextAreaElement && ctx.root.contains(active)) {
|
||||
const front = UNIT_PREFIX.includes(unit);
|
||||
const s = front ? 0 : (active.selectionStart ?? active.value.length);
|
||||
const e = front ? 0 : (active.selectionEnd ?? active.value.length);
|
||||
const was = active.selectionStart ?? active.value.length;
|
||||
active.value = active.value.slice(0, s) + unit + active.value.slice(e);
|
||||
const at = front ? was + unit.length : s + unit.length;
|
||||
active.setSelectionRange(at, at);
|
||||
if (UNIT_PREFIX.includes(unit)) {
|
||||
const next = prefixUnit(active.value, unit);
|
||||
const at = was + next.length - active.value.length;
|
||||
active.value = next;
|
||||
active.setSelectionRange(at, at);
|
||||
} else {
|
||||
const s = was;
|
||||
const e = active.selectionEnd ?? active.value.length;
|
||||
active.value = active.value.slice(0, s) + unit + active.value.slice(e);
|
||||
active.setSelectionRange(s + unit.length, s + unit.length);
|
||||
}
|
||||
active.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
} else if (unitAsFormat.checked) {
|
||||
@@ -422,11 +436,7 @@ export function mountToolbar(ctx: SpreadsheetContext): PartHandle {
|
||||
const sheet = ctx.sheet();
|
||||
const key = toA1(r, c);
|
||||
const now = cellToText(sheet.칸[key]);
|
||||
const text = UNIT_PREFIX.includes(unit)
|
||||
? now.startsWith(unit)
|
||||
? now
|
||||
: unit + now // 앞 단위 — 「300」 → 「Φ300」
|
||||
: now + unit;
|
||||
const text = UNIT_PREFIX.includes(unit) ? prefixUnit(now, unit) : now + unit;
|
||||
ctx.dispatch({ 종류: "칸", 시트: sheet.id, 칸: { [key]: textToCell(text, sheet.칸[key]) } });
|
||||
}
|
||||
renderRecent(pushRecentUnit(unit));
|
||||
|
||||
Reference in New Issue
Block a user