fix(编辑能力): 修复文本对齐与转换偏差
build.yaml / build (push) Successful in 48s

This commit is contained in:
xiaoqidun committed 2026-10-27 22:38:16 +08:00
1 parent dfea3d60fd
commit f246b0f543
4 files changed
+144 -113

No files matched your search

+4 -4
View File
@@ -4142,8 +4142,8 @@ async function loadRichText(item, firstFace, tab = documentTab(), firstData = nu
if (tab.closed || wasmSeq !== tab.state.wasmSeq) throw new Error("文档已更改");
return callTabWASM(tab, name, ...args);
};
const prepared = reflow ? await callWASM("ofdgoGetRichText", item.index, item.id, true) : null;
const model = prepared?.model || item.richText || await callWASM("ofdgoGetRichText", item.index, item.id);
const prepared = item.richText ? { model: item.richText, frame: item.textFrame } : await callWASM("ofdgoGetRichText", item.index, item.id, reflow);
const model = prepared.model;
const remaining = firstData ? { ...model, runs: model.runs.filter(run => run.format.font !== item.font) } : model;
const fontData = remaining.runs.length ? await callWASM("ofdgoRichTextFonts", JSON.stringify(remaining)) : [];
const resources = new Map(fontData.map(font => [font.key, font.data]));
@@ -4155,7 +4155,7 @@ async function loadRichText(item, firstFace, tab = documentTab(), firstData = nu
if (tab.closed || wasmSeq !== tab.state.wasmSeq) throw new Error("文档已更改");
faces.set(id, face);
}
return { model, faces, resources, frame: prepared?.frame };
return { model, faces, resources, frame: prepared.frame, reflow };
}
async function ensureRichInput(reflow = false) {
@@ -4256,7 +4256,7 @@ async function validateRichText(item, model, width, fonts = []) {
async function saveRichText(item, model, fonts = [], box = item) {
const tab = documentTab(), openSeq = state.openSeq, wasmSeq = state.wasmSeq;
const boundary = { x: box.x, y: box.y, width: box.width, height: box.height };
if (item.richReflow) { boundary.reflow = true; boundary.width = item.textFrame.width; }
if (item.richReflow) boundary.reflow = true;
if (box.frameWidth !== undefined) Object.assign(boundary, { frameWidth: box.frameWidth, frameOffset: box.frameOffset || 0 });
fonts = await validateRichText(item, model, box.frameWidth ?? item.textFrame?.width ?? item.width, fonts);
if (tab.closed || !isForegroundDocument(tab) || tab.state.openSeq !== openSeq || tab.state.wasmSeq !== wasmSeq) return false;
+1 -3
View File
@@ -1958,12 +1958,10 @@ export class CanvasEditor {
const value = editTextValue(editing.input);
const session = new RichTextSession(this, rich.model, rich.faces, rich.fonts, rich.resources);
const base = { ...session.typing }, fonts = new Map();
const scale = rich.frame ? sourceTextScale(editing) : 1;
const current = { value, style: editing.style, face: editing.face, fontData: editing.fontData, fontChoice: editing.fontChoice, caret };
const values = editing.history ? editing.history.entries.slice(0, editing.history.index + 1) : [{ value: editing.item.text }];
for (const entry of [...values, current]) {
const format = { ...base, ...entry.style };
if (entry.style?.size) format.size *= scale;
if (entry.fontData) {
let key = fonts.get(entry.fontData);
if (!key) {
@@ -1982,7 +1980,7 @@ export class CanvasEditor {
}
if (rich.frame) {
editing.frame = rich.frame;
editing.item = { ...editing.item, richReflow: true, textFrame: rich.frame };
editing.item = { ...editing.item, richReflow: rich.reflow, textFrame: rich.frame };
Object.assign(editing.input.style, { whiteSpace: rich.model.layout.wrap ? "pre-wrap" : "pre", textIndent: "0px", letterSpacing: "0px" });
}
editing.rich = session;