diff --git a/bundled-addons/pdf-editor/editor.js b/bundled-addons/pdf-editor/editor.js index 6f258e0..2e2818a 100644 --- a/bundled-addons/pdf-editor/editor.js +++ b/bundled-addons/pdf-editor/editor.js @@ -560,7 +560,9 @@ const selbar = $("selbar"); function paintSelectionBar(id) { const a = id && session.model ? session.model.annot(id) : null; if (!a) { selbar.hidden = true; return; } - const isText = a.kind === "text"; + // A replaced run is text too. Leaving it out meant the one mark made of + // words offered no way to change them — the exact gap this bar exists for. + const isText = a.kind === "text" || a.kind === "textedit"; const isShape = a.kind === "rect" || a.kind === "ellipse"; $("sb-edit").hidden = !isText; $("sb-textsize").hidden = !isText; @@ -633,13 +635,13 @@ $("sb-bigger").addEventListener("click", () => stepTextSize(1)); function toggleTextStyle(which) { const a = session.model?.annot(session.tools?.selected); - if (!a || a.kind !== "text") return; + if (!a || (a.kind !== "text" && a.kind !== "textedit")) return; delete a._w; // the glyphs change width; re-measure session.tools.patchSelected({ [which]: !a[which] }); } function stepTextSize(dir) { const a = session.model?.annot(session.tools?.selected); - if (!a || a.kind !== "text") return; + if (!a || (a.kind !== "text" && a.kind !== "textedit")) return; const steps = [6, 8, 9, 10, 11, 12, 14, 16, 18, 24, 30, 36, 48, 60, 72, 96]; const at = a.size || 12; const next = dir > 0 ? steps.find((v) => v > at + 0.01) : [...steps].reverse().find((v) => v < at - 0.01); @@ -657,20 +659,33 @@ async function onTextModal(id, at) { const existing = id ? session.model?.annot(id) : null; $("modal-text-title").textContent = existing ? "Edit text" : "Text stamp"; $("text-body").value = existing ? existing.text : ""; - $("text-size").value = String(existing ? existing.size || 12 : 12); + // A run lifted out of a document is whatever size the document set — 11 pt, + // 9.5 pt — and the picker only lists round numbers. Without this the select + // falls back to empty and the size silently becomes 12 on the way out. + const wanted = existing ? existing.size || 12 : 12; + const sizeSel = $("text-size"); + if (![...sizeSel.options].some((o) => Number(o.value) === Number(wanted))) { + const opt = document.createElement("option"); + opt.value = String(wanted); + opt.textContent = String(Math.round(wanted * 10) / 10); + opt.dataset.adhoc = "1"; + sizeSel.append(opt); + } + sizeSel.value = String(wanted); $("text-bold").classList.toggle("active", !!existing?.bold); $("text-italic").classList.toggle("active", !!existing?.italic); $("text-warn").hidden = true; const p = openModal("modal-text"); setTimeout(() => { $("text-body").focus(); $("text-body").select(); }, 30); const ok = await p; - if (!ok) return null; const props = { text: $("text-body").value, - size: parseFloat($("text-size").value) || 12, + size: parseFloat($("text-size").value) || wanted, bold: $("text-bold").classList.contains("active"), italic: $("text-italic").classList.contains("active"), }; + for (const o of [...$("text-size").options]) if (o.dataset.adhoc) o.remove(); + if (!ok) return null; return existing ? session.tools.updateText(id, props) : session.tools.placeText(at, props); } for (const b of [$("text-bold"), $("text-italic")]) { @@ -1066,7 +1081,7 @@ window.addEventListener("keydown", (e) => { if (e.key === "Enter") { const sel = session.tools?.selected; const a = sel && session.model?.annot(sel); - if (a?.kind === "text") { onTextModal(sel, null); e.preventDefault(); } + if (a?.kind === "text" || a?.kind === "textedit") { onTextModal(sel, null); e.preventDefault(); } return; } if (e.key === "+" || e.key === "=") { session.strip?.stepScale(1); syncZoomSelect(); e.preventDefault(); return; } diff --git a/bundled-addons/pdf-editor/lib/tools.js b/bundled-addons/pdf-editor/lib/tools.js index 2decfe9..c77edf0 100644 --- a/bundled-addons/pdf-editor/lib/tools.js +++ b/bundled-addons/pdf-editor/lib/tools.js @@ -206,7 +206,7 @@ export class Tools { e.preventDefault(); if (double) { const a = this.model.annot(id); - if (a?.kind === "text") { this.host.editText?.(id, null); return; } + if (a?.kind === "text" || a?.kind === "textedit") { this.host.editText?.(id, null); return; } } this.drag = { kind: "move", uid: hit.uid, id, x0: x, y0: y, orig: structuredClone(this.model.annot(id)), cx: e.clientX, cy: e.clientY, moved: false };