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:
Abdo 2024-02-07 06:42:47 +03:00 committed by GitHub
parent 85a8824c8c
commit 80c14aa6e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 11 deletions

View file

@ -66,6 +66,7 @@ message GetImageOcclusionNoteResponse {
message ImageOcclusion {
repeated ImageOcclusionShape shapes = 1;
uint32 ordinal = 2;
}
message ImageOcclusionNote {

View file

@ -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()
}

View file

@ -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;

View file

@ -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));
}
}

View file

@ -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;