mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Maintain original IO cloze order in editing mode (#2987)
* Maintain original IO cloze order in editing mode * Fix ordinal propery name
This commit is contained in:
parent
85a8824c8c
commit
80c14aa6e9
5 changed files with 22 additions and 11 deletions
|
@ -66,6 +66,7 @@ message GetImageOcclusionNoteResponse {
|
|||
|
||||
message ImageOcclusion {
|
||||
repeated ImageOcclusionShape shapes = 1;
|
||||
uint32 ordinal = 2;
|
||||
}
|
||||
|
||||
message ImageOcclusionNote {
|
||||
|
|
|
@ -331,8 +331,11 @@ pub fn parse_image_occlusions(text: &str) -> Vec<ImageOcclusion> {
|
|||
}
|
||||
|
||||
occlusions
|
||||
.values()
|
||||
.map(|v| ImageOcclusion { shapes: v.to_vec() })
|
||||
.iter()
|
||||
.map(|(k, v)| ImageOcclusion {
|
||||
ordinal: *k as u32,
|
||||
shapes: v.to_vec(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,11 @@ export class Shape {
|
|||
*/
|
||||
occludeInactive?: boolean;
|
||||
/* Cloze ordinal */
|
||||
ordinal = 0;
|
||||
ordinal: number | undefined;
|
||||
|
||||
constructor(
|
||||
{ left = 0, top = 0, fill = SHAPE_MASK_COLOR, occludeInactive, ordinal = 0 }: ConstructorParams<Shape> = {},
|
||||
{ left = 0, top = 0, fill = SHAPE_MASK_COLOR, occludeInactive, ordinal = undefined }: ConstructorParams<Shape> =
|
||||
{},
|
||||
) {
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
|
|
|
@ -21,7 +21,10 @@ export function extractShapesFromClozedField(
|
|||
const group: Shape[] = [];
|
||||
for (const shape of occlusion.shapes) {
|
||||
if (isValidType(shape.shape)) {
|
||||
const props = Object.fromEntries(shape.properties.map(prop => [prop.name, prop.value]));
|
||||
const props: Record<string, any> = Object.fromEntries(
|
||||
shape.properties.map(prop => [prop.name, prop.value]),
|
||||
);
|
||||
props.ordinal = occlusion.ordinal;
|
||||
group.push(buildShape(shape.shape, props));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,13 +148,16 @@ function shapeOrShapesToCloze(
|
|||
addKeyValue("oi", "1");
|
||||
}
|
||||
|
||||
let ordinal: number;
|
||||
if (type === "text") {
|
||||
ordinal = 0;
|
||||
} else {
|
||||
ordinal = index + 1;
|
||||
// Maintain existing ordinal in editing mode
|
||||
let ordinal = shapeOrShapes.ordinal;
|
||||
if (ordinal === undefined) {
|
||||
if (type === "text") {
|
||||
ordinal = 0;
|
||||
} else {
|
||||
ordinal = index + 1;
|
||||
}
|
||||
shapeOrShapes.ordinal = ordinal;
|
||||
}
|
||||
shapeOrShapes.ordinal = ordinal;
|
||||
text = `{{c${ordinal}::image-occlusion:${type}${text}}}<br>`;
|
||||
|
||||
return text;
|
||||
|
|
Loading…
Reference in a new issue