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 { message ImageOcclusion {
repeated ImageOcclusionShape shapes = 1; repeated ImageOcclusionShape shapes = 1;
uint32 ordinal = 2;
} }
message ImageOcclusionNote { message ImageOcclusionNote {

View file

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

View file

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

View file

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

View file

@ -148,13 +148,16 @@ function shapeOrShapesToCloze(
addKeyValue("oi", "1"); addKeyValue("oi", "1");
} }
let ordinal: number; // Maintain existing ordinal in editing mode
let ordinal = shapeOrShapes.ordinal;
if (ordinal === undefined) {
if (type === "text") { if (type === "text") {
ordinal = 0; ordinal = 0;
} else { } else {
ordinal = index + 1; 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;