Keep pasted card images in description drafts
A pasted image arrives while it still loads, so the draft save did not start. A close of the card then cleared the image data from memory. The draft kept the text and a reference to an image that RuneStone never saved. - A second draft file, <card hex>.images.json, keeps the data of the images that only the draft uses. - Only a save of the description or the card writes image files. Save and Cancel empty the draft and its image record, so a discarded draft leaves no image file. - A reopened card restores the images of its draft. The draft saves after a pasted image finishes loading. A card save also writes a cover image that only the draft has. New tests: the pmDraftImages smoke test and the description-draft unit tests. (cherry picked from commit d9653da579bf8cfc0edd2457f72e658c9fe00fd6)
This commit is contained in:
@@ -1051,7 +1051,11 @@ export function mountPM(
|
||||
description,
|
||||
(name, action) => button(tr(name), action, name === "Actual size" ? "expand" : "image"),
|
||||
(name, action) => iconButton(name, "close", action),
|
||||
(loading) => { save.disabled = loading || busy || !title.value.trim(); descriptionEditor.updateLoading(); },
|
||||
(loading) => {
|
||||
save.disabled = loading || busy || !title.value.trim(); descriptionEditor.updateLoading();
|
||||
// The input event of a pasted image comes while the image loads. Save the draft after the load.
|
||||
if (!loading) scheduleDraft();
|
||||
},
|
||||
task?.attachments,
|
||||
);
|
||||
const formattingIcons: Record<string, keyof typeof icons> = {
|
||||
@@ -1064,9 +1068,10 @@ export function mountPM(
|
||||
let descriptionSaving = false;
|
||||
let draftTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let draftEdited = false;
|
||||
const draftReady = draft?.load().then(body => {
|
||||
const draftReady = draft && Promise.all([draft.load(), draft.loadImages()]).then(([body, draftImages]) => {
|
||||
if (body !== null && !draftEdited && dialog.isConnected) {
|
||||
descriptionEditor.restoreDraft(body);
|
||||
images.restore(draftImages);
|
||||
updateDescriptionBadge(task!.id, body !== task!.body);
|
||||
}
|
||||
});
|
||||
@@ -1074,8 +1079,13 @@ export function mountPM(
|
||||
clearTimeout(draftTimer);
|
||||
await draftReady;
|
||||
if (!draft || !task) return;
|
||||
await images.save(description.value);
|
||||
await draft.save(description.value === task.body ? null : description.value);
|
||||
const body = description.value;
|
||||
// The draft keeps the data of its unsaved images. The image files come only with a save of the description or the card.
|
||||
await draft.save(body === task.body ? null : body, images.draftImages(body));
|
||||
};
|
||||
const scheduleDraft = () => {
|
||||
clearTimeout(draftTimer);
|
||||
if (draft && !images.isLoading()) draftTimer = setTimeout(() => { void flushDraft().catch(reportDraftError); }, 300);
|
||||
};
|
||||
const reportDraftError = (reason: unknown) => { error.textContent = errorText(reason); };
|
||||
void draftReady?.catch(reportDraftError);
|
||||
@@ -1113,8 +1123,7 @@ export function mountPM(
|
||||
description.addEventListener("input", () => {
|
||||
draftEdited = true;
|
||||
if (task) updateDescriptionBadge(task.id, description.value !== task.body);
|
||||
clearTimeout(draftTimer);
|
||||
if (draft && !images.isLoading()) draftTimer = setTimeout(() => { void flushDraft().catch(reportDraftError); }, 300);
|
||||
scheduleDraft();
|
||||
});
|
||||
const useSharedChoices = sharedChoice;
|
||||
const updateChoice = sharedChoices.update;
|
||||
@@ -1549,7 +1558,8 @@ export function mountPM(
|
||||
const ok = await perform(
|
||||
async () => {
|
||||
await flushDraft();
|
||||
await images.save(body);
|
||||
// The cover can be an image that only the description draft has.
|
||||
await images.save(body, cover.value ? [cover.value] : []);
|
||||
const existingIds = new Set(store.tasks.map(candidate => candidate.id));
|
||||
await (task && boardSelect.value && (boardSelect.value !== originalBoardId || (!store.board.reference && listChanged))
|
||||
? store.saveToBoard(task, boardSelect.value, listSelect.value || null, { ...fields, body })
|
||||
|
||||
Reference in New Issue
Block a user