mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
1 parent
f76a1ecd1a
commit
143d5e7f92
1 file changed
+13
-8
+13
-8
@@ -705,7 +705,7 @@ el.editorTools.addEventListener("scroll", () => fontPicker.position());
|
|||||||
const canvasEditor = new CanvasEditor(el.viewerPanel, {
|
const canvasEditor = new CanvasEditor(el.viewerPanel, {
|
||||||
textControls: [el.textFont, el.textFontToggle, el.textFontAdd, el.textFontList, el.textSize, el.textColor, textBackground, ...textFormatButtons, el.undoButton, el.redoButton, el.saveButton, el.saveAsButton, el.fontInput, document.querySelector("#textReflow")],
|
textControls: [el.textFont, el.textFontToggle, el.textFontAdd, el.textFontList, el.textSize, el.textColor, textBackground, ...textFormatButtons, el.undoButton, el.redoButton, el.saveButton, el.saveAsButton, el.fontInput, document.querySelector("#textReflow")],
|
||||||
keepTextFocus: () => fontPicker.open || el.closePanel.open || canvasEditor.input?.fontDialog,
|
keepTextFocus: () => fontPicker.open || el.closePanel.open || canvasEditor.input?.fontDialog,
|
||||||
textClipboardScope: () => `${documentTab().id}:${state.wasmSeq}:${state.fileName}:${state.doc?.documents?.[state.doc.documentIndex || 0]?.root}:${state.doc?.documentIndex || 0}:${state.doc?.documentVersion || ""}:${state.editorInfo?.revision ?? ""}`,
|
textClipboardScope: () => `${documentTab().id}:${documentContentKey(state)}:${state.editorInfo?.revision ?? ""}`,
|
||||||
getTextClipboard: () => workspace.textClipboard,
|
getTextClipboard: () => workspace.textClipboard,
|
||||||
setTextClipboard: clipboard => { workspace.textClipboard = clipboard; },
|
setTextClipboard: clipboard => { workspace.textClipboard = clipboard; },
|
||||||
scrollBy: (x, y) => { el.viewerPanel.scrollLeft += x; pageView.scrollViewerBy(y); },
|
scrollBy: (x, y) => { el.viewerPanel.scrollLeft += x; pageView.scrollViewerBy(y); },
|
||||||
@@ -3386,6 +3386,11 @@ function documentEntryKey(entry) {
|
|||||||
return JSON.stringify([entry?.root, entry?.id]);
|
return JSON.stringify([entry?.root, entry?.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function documentContentKey(state) {
|
||||||
|
const index = state.doc?.documentIndex || 0;
|
||||||
|
return JSON.stringify([state.wasmSeq, index, documentEntryKey(state.doc?.documents?.[index]), state.doc?.documentVersion || ""]);
|
||||||
|
}
|
||||||
|
|
||||||
async function openDocumentManagement() {
|
async function openDocumentManagement() {
|
||||||
if (!state.editing || !state.ready || state.exporting || document.body.hasAttribute("data-busy")) return;
|
if (!state.editing || !state.ready || state.exporting || document.body.hasAttribute("data-busy")) return;
|
||||||
const index = state.doc.documentIndex || 0;
|
const index = state.doc.documentIndex || 0;
|
||||||
@@ -8512,7 +8517,7 @@ async function resumeDocumentPanels(tab) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function documentPanelScope(state) {
|
function documentPanelScope(state) {
|
||||||
return JSON.stringify([state.doc?.documentIndex || 0, state.doc?.documentVersion || "", state.editorInfo?.revision ?? null]);
|
return JSON.stringify([documentContentKey(state), state.editorInfo?.revision ?? null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderResourceTabs() {
|
function renderResourceTabs() {
|
||||||
@@ -8578,7 +8583,7 @@ async function loadManagedResources(tab = documentTab()) {
|
|||||||
const state = tab.state, resourceManager = tab.resources;
|
const state = tab.state, resourceManager = tab.resources;
|
||||||
const sequence = state.openSeq;
|
const sequence = state.openSeq;
|
||||||
const manager = resourceManager;
|
const manager = resourceManager;
|
||||||
const scope = JSON.stringify([tab.id, state.doc.documentIndex || 0, state.doc.documentVersion || "", state.editing]);
|
const scope = JSON.stringify([tab.id, documentContentKey(state), state.editing]);
|
||||||
if (resourceManager.scope === scope) {
|
if (resourceManager.scope === scope) {
|
||||||
if (isForegroundDocument(tab)) rememberResourceView();
|
if (isForegroundDocument(tab)) rememberResourceView();
|
||||||
}
|
}
|
||||||
@@ -10515,7 +10520,7 @@ function copyEditorSelection(event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const index = items[0].index, ids = items.map(item => item.id);
|
const index = items[0].index, ids = items.map(item => item.id);
|
||||||
const clipboard = { tab, token: crypto.randomUUID(), source: `${tab.id}:${state.wasmSeq}:${state.doc.documentIndex || 0}:${state.doc.documentVersion || ""}`, page: state.doc.pages[index].id, bounds: selectionBounds(items), x: 0, y: 0, cut };
|
const clipboard = { tab, token: crypto.randomUUID(), source: `${tab.id}:${documentContentKey(state)}`, page: state.doc.pages[index].id, bounds: selectionBounds(items), x: 0, y: 0, cut };
|
||||||
if (canvasEditor.nudge) {
|
if (canvasEditor.nudge) {
|
||||||
clipboard.bounds.x += canvasEditor.nudge.x;
|
clipboard.bounds.x += canvasEditor.nudge.x;
|
||||||
clipboard.bounds.y += canvasEditor.nudge.y;
|
clipboard.bounds.y += canvasEditor.nudge.y;
|
||||||
@@ -10531,7 +10536,7 @@ function copyEditorSelection(event) {
|
|||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
const capture = () => {
|
const capture = () => {
|
||||||
if (tab.closed || !state.editing || workspace.objectClipboard !== clipboard || state.objectClipboardToken !== clipboard.token
|
if (tab.closed || !state.editing || workspace.objectClipboard !== clipboard || state.objectClipboardToken !== clipboard.token
|
||||||
|| clipboard.source !== `${tab.id}:${state.wasmSeq}:${state.doc.documentIndex || 0}:${state.doc.documentVersion || ""}`
|
|| clipboard.source !== `${tab.id}:${documentContentKey(state)}`
|
||||||
|| state.doc.pages[index]?.id !== clipboard.page) return false;
|
|| state.doc.pages[index]?.id !== clipboard.page) return false;
|
||||||
const openSeq = state.openSeq, revision = state.editorInfo.revision;
|
const openSeq = state.openSeq, revision = state.editorInfo.revision;
|
||||||
return callTabWASM(tab, "ofdgoCaptureObjects", index, ids, clipboard.token).then(async () => {
|
return callTabWASM(tab, "ofdgoCaptureObjects", index, ids, clipboard.token).then(async () => {
|
||||||
@@ -10596,14 +10601,14 @@ async function pasteEditorContent(event) {
|
|||||||
setStatus("复制内容已失效,请重新复制");
|
setStatus("复制内容已失效,请重新复制");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const openSeq = state.openSeq, identity = `${state.wasmSeq}:${state.doc.documentIndex || 0}:${state.doc.documentVersion || ""}`;
|
const openSeq = state.openSeq, identity = documentContentKey(state);
|
||||||
const local = state.objectClipboardToken === clipboard.token;
|
const local = state.objectClipboardToken === clipboard.token;
|
||||||
if (!await (local ? clipboard.ready : prepareObjectClipboard(clipboard, tab)) || !isForegroundDocument(tab) || openSeq !== state.openSeq || index !== state.pageIndex || workspace.objectClipboard !== clipboard) return;
|
if (!await (local ? clipboard.ready : prepareObjectClipboard(clipboard, tab)) || !isForegroundDocument(tab) || openSeq !== state.openSeq || index !== state.pageIndex || workspace.objectClipboard !== clipboard) return;
|
||||||
if (identity !== `${state.wasmSeq}:${state.doc.documentIndex || 0}:${state.doc.documentVersion || ""}` || local && state.objectClipboardToken !== clipboard.token) return;
|
if (identity !== documentContentKey(state) || local && state.objectClipboardToken !== clipboard.token) return;
|
||||||
if (!state.editing || formDialogOpen() || document.body.hasAttribute("data-busy") || canvasEditor.input || canvasEditor.crop || canvasEditor.drag || canvasEditor.nudge || canvasEditor.nudgeCommit) return;
|
if (!state.editing || formDialogOpen() || document.body.hasAttribute("data-busy") || canvasEditor.input || canvasEditor.crop || canvasEditor.drag || canvasEditor.nudge || canvasEditor.nudgeCommit) return;
|
||||||
if (!pageCan("insert")) return;
|
if (!pageCan("insert")) return;
|
||||||
const visible = visiblePageBounds(index), bounds = clipboard.bounds;
|
const visible = visiblePageBounds(index), bounds = clipboard.bounds;
|
||||||
const target = `${tab.id}:${state.wasmSeq}:${state.doc.documentIndex || 0}:${state.doc.documentVersion || ""}`;
|
const target = `${tab.id}:${documentContentKey(state)}`;
|
||||||
const offset = (clipboard.target || clipboard.source) === target && (clipboard.targetPage || clipboard.page) === page.id ? { x: clipboard.x + (clipboard.cut ? 0 : 3), y: clipboard.y + (clipboard.cut ? 0 : 3) } : { x: 0, y: 0 };
|
const offset = (clipboard.target || clipboard.source) === target && (clipboard.targetPage || clipboard.page) === page.id ? { x: clipboard.x + (clipboard.cut ? 0 : 3), y: clipboard.y + (clipboard.cut ? 0 : 3) } : { x: 0, y: 0 };
|
||||||
for (const [axis, size] of [["x", "width"], ["y", "height"]]) {
|
for (const [axis, size] of [["x", "width"], ["y", "height"]]) {
|
||||||
const position = bounds[axis] + offset[axis];
|
const position = bounds[axis] + offset[axis];
|
||||||
|
|||||||
Reference in new issue
Block a user