mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Fix modified polygon not being saved when editing IO note (#2762)
This commit is contained in:
parent
56f7d54900
commit
f8edbcc686
2 changed files with 10 additions and 12 deletions
|
@ -13,6 +13,7 @@ import { notesDataStore, tagsWritable, zoomResetValue } from "./store";
|
|||
import Toast from "./Toast.svelte";
|
||||
import { addShapesToCanvasFromCloze } from "./tools/add-from-cloze";
|
||||
import { enableSelectable, moveShapeToCanvasBoundaries } from "./tools/lib";
|
||||
import { modifiedPolygon } from "./tools/tool-polygon";
|
||||
import { undoStack } from "./tools/tool-undo-redo";
|
||||
import type { Size } from "./types";
|
||||
|
||||
|
@ -103,7 +104,13 @@ function initCanvas(onChange: () => void): fabric.Canvas {
|
|||
canvas.uniformScaling = false;
|
||||
canvas.uniScaleKey = "none";
|
||||
moveShapeToCanvasBoundaries(canvas);
|
||||
canvas.on("object:modified", onChange);
|
||||
canvas.on("object:modified", (evt) => {
|
||||
if (evt.target instanceof fabric.Polygon) {
|
||||
modifiedPolygon(canvas, evt.target);
|
||||
undoStack.onObjectModified();
|
||||
}
|
||||
onChange();
|
||||
});
|
||||
canvas.on("object:removed", onChange);
|
||||
return canvas;
|
||||
}
|
||||
|
|
|
@ -193,15 +193,11 @@ const generatePolygon = (canvas: fabric.Canvas, pointsList): void => {
|
|||
undoStack.onObjectAdded(polygon.id);
|
||||
}
|
||||
|
||||
polygon.on("modified", () => {
|
||||
modifiedPolygon(canvas, polygon);
|
||||
undoStack.onObjectModified();
|
||||
});
|
||||
|
||||
toggleDrawPolygon(canvas);
|
||||
};
|
||||
|
||||
const modifiedPolygon = (canvas: fabric.Canvas, polygon: fabric.Polygon): void => {
|
||||
// https://github.com/fabricjs/fabric.js/issues/6522
|
||||
export const modifiedPolygon = (canvas: fabric.Canvas, polygon: fabric.Polygon): void => {
|
||||
const matrix = polygon.calcTransformMatrix();
|
||||
const transformedPoints = polygon.get("points")
|
||||
.map(function(p) {
|
||||
|
@ -221,11 +217,6 @@ const modifiedPolygon = (canvas: fabric.Canvas, polygon: fabric.Polygon): void =
|
|||
noScaleCache: false,
|
||||
});
|
||||
|
||||
polygon1.on("modified", () => {
|
||||
modifiedPolygon(canvas, polygon1);
|
||||
undoStack.onObjectModified();
|
||||
});
|
||||
|
||||
canvas.remove(polygon);
|
||||
canvas.add(polygon1);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue