Skip to content

Commit 20eb6ca

Browse files
Merge pull request #14044 from calixteman/bug1719148
Annotations - Avoid empty value in text field when storage contains something for it (bug 1719148)
2 parents 2375318 + eb762ad commit 20eb6ca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/display/annotation_storage.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ class AnnotationStorage {
4242
* @returns {Object}
4343
*/
4444
getValue(key, defaultValue) {
45-
return this._storage.get(key) ?? defaultValue;
45+
const value = this._storage.get(key);
46+
if (value === undefined) {
47+
return defaultValue;
48+
}
49+
50+
return Object.assign(defaultValue, value);
4651
}
4752

4853
/**

test/unit/annotation_storage_spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ describe("AnnotationStorage", function () {
3535
}).value;
3636
expect(value).toEqual("hello world");
3737
});
38+
39+
it("should get set values and default ones in the annotation storage", function () {
40+
const annotationStorage = new AnnotationStorage();
41+
annotationStorage.setValue("123A", {
42+
value: "hello world",
43+
hello: "world",
44+
});
45+
46+
const result = annotationStorage.getValue("123A", {
47+
value: "an other string",
48+
world: "hello",
49+
});
50+
expect(result).toEqual({
51+
value: "hello world",
52+
hello: "world",
53+
world: "hello",
54+
});
55+
});
3856
});
3957

4058
describe("SetValue", function () {

0 commit comments

Comments
 (0)