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 {
|
message ImageOcclusion {
|
||||||
repeated ImageOcclusionShape shapes = 1;
|
repeated ImageOcclusionShape shapes = 1;
|
||||||
|
uint32 ordinal = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ImageOcclusionNote {
|
message ImageOcclusionNote {
|
||||||
|
|
|
@ -331,8 +331,11 @@ pub fn parse_image_occlusions(text: &str) -> Vec<ImageOcclusion> {
|
||||||
}
|
}
|
||||||
|
|
||||||
occlusions
|
occlusions
|
||||||
.values()
|
.iter()
|
||||||
.map(|v| ImageOcclusion { shapes: v.to_vec() })
|
.map(|(k, v)| ImageOcclusion {
|
||||||
|
ordinal: *k as u32,
|
||||||
|
shapes: v.to_vec(),
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,11 @@ export class Shape {
|
||||||
*/
|
*/
|
||||||
occludeInactive?: boolean;
|
occludeInactive?: boolean;
|
||||||
/* Cloze ordinal */
|
/* Cloze ordinal */
|
||||||
ordinal = 0;
|
ordinal: number | undefined;
|
||||||
|
|
||||||
constructor(
|
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.left = left;
|
||||||
this.top = top;
|
this.top = top;
|
||||||
|
|
|
@ -21,7 +21,10 @@ export function extractShapesFromClozedField(
|
||||||
const group: Shape[] = [];
|
const group: Shape[] = [];
|
||||||
for (const shape of occlusion.shapes) {
|
for (const shape of occlusion.shapes) {
|
||||||
if (isValidType(shape.shape)) {
|
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));
|
group.push(buildShape(shape.shape, props));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,13 +148,16 @@ function shapeOrShapesToCloze(
|
||||||
addKeyValue("oi", "1");
|
addKeyValue("oi", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
let ordinal: number;
|
// Maintain existing ordinal in editing mode
|
||||||
if (type === "text") {
|
let ordinal = shapeOrShapes.ordinal;
|
||||||
ordinal = 0;
|
if (ordinal === undefined) {
|
||||||
} else {
|
if (type === "text") {
|
||||||
ordinal = index + 1;
|
ordinal = 0;
|
||||||
|
} else {
|
||||||
|
ordinal = index + 1;
|
||||||
|
}
|
||||||
|
shapeOrShapes.ordinal = ordinal;
|
||||||
}
|
}
|
||||||
shapeOrShapes.ordinal = ordinal;
|
|
||||||
text = `{{c${ordinal}::image-occlusion:${type}${text}}}<br>`;
|
text = `{{c${ordinal}::image-occlusion:${type}${text}}}<br>`;
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
|
Loading…
Reference in a new issue